#include<iostream>
using namespace std;

int main() {
	int n;
	while (cin >> n, n) {
		int ar[25];
		for (int i = 0;i < n;i++)cin >> ar[i];

		int o = 32;
		int c = 1;
		while (o > 0) {
			if (c % 2 == 1) {
				int a = (o - 1) % 5;
				o -= a;
				cout << o << endl;
			}
			else {
				int a = (c / 2) % n-1;
				if (a == -1)a += n;
				o -= ar[a];
				if (o < 0)o = 0;
				cout << o << endl;
			}
			c++;
		}

	}
	return 0;
}