// 2011/02/06 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int i;
		cin >> i;
		if(i==0)
			break;

		int jir[25];
		for(int j=0; j<i; j++)
			cin >> jir[j];

		int n = 32;
		bool flg = true;
		int jir_i = 0;
		while(n>0){
			if(flg){
				int taro = (n-1)%5;
				if(taro>n)
					taro = n;
				n -= taro;
				cout << n << endl;
				flg = false;
			}
			else{
				int jiro = jir[jir_i];
				jir_i = (jir_i+1)%i;
				if(jiro>n)
					jiro = n;
				n -= jiro;
				cout << n << endl;
				flg = true;
			}
		}
	}

	return 0;
}