#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		int cnt=0,a[25],all=32;
		for(int i=0;i<n;i++)cin>>a[i];
		bool turn=true;//true:?????????false:?¬????
		while(all>0){
			if(turn){
				all=all-(all-1)%5;
				if(all<0)all=0;
				cout<<all<<endl;
				turn=false;
			}else{
				all-=a[cnt];
				if(all<0)all=0;
				cout<<all<<endl;
				cnt++;
				if(cnt==n)cnt=0;
				turn=true;
			}
		}
	}
}