#include<iostream>
using namespace std;

int main(){
  while(true){
    int n;
    cin>>n;
    if(n==0)break;
    int sequence[n];
    for(int i=0;i<n;i++){
      cin>>sequence[i];
    }
    int ohaziki=32;int now=0;
    while(ohaziki>0){
      ohaziki=ohaziki-(ohaziki-1)%5;
      if(ohaziki<0)ohaziki=0;
      cout<<ohaziki<<endl;
      ohaziki=ohaziki-sequence[now];
      if(ohaziki<0)ohaziki=0;
      cout<<ohaziki<<endl;
      now++;
      if(now>n-1)now=0;
    }
  }
}