#include <iostream>
#include <cstdio>
#include <string>
#include <queue>
using namespace std;

int main(void){
	while(1){
		int n;
		vector<int> num;
		cin >> n;
		if(n == 0) break;

		for(int i=0; i<n; i++){
			int t;
			cin >> t;
			num.push_back(t);
		}

		int a = 32;
		int i=0;
		while(1){
			a -= (a-1)	% 5;
			if(a < 0) {
				cout << 0 << endl;
				break;
			}
			cout << a << endl;
			a -= num[i % num.size()];
			i++;
			if(a < 0) {
				cout << 0 << endl;
				break;
			}
			cout << a << endl;
		}

	}


	return 0;
}