#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

int main(){
	int N;
	while(cin>>N,N){
		int A[25];
		for(int i=0;i<N;i++){
			cin>>A[i];
		}
		int c = 32;
		for(int i=0;c!=0;i++){
			c = max(c-(c-1)%5,0);
			printf("%d\n",c);
			if(c==0) break;
			c = max(c-A[i%N],0);
			printf("%d\n",c);
		}
	}
	return 0;
}