#include <bits/stdc++.h>

using namespace std;


int TakeQueue[25];

void judge(const int n) {
	int sum,i;
	bool flag;

	sum = 32;
	i = 0;
	flag = true;
	while (sum != 1) {
		if (flag) {
			sum -= (sum - 1) % 5;
			cout << sum << endl;
			flag = false;
		}
		else {
			sum -= TakeQueue[i];
			i = (i + 1) % n;
			cout << sum << endl;
			flag = true;
		}
	}
	cout << "0" << endl;
}


int main(void) {
	int n;

	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			cin >> TakeQueue[i];
		}
		judge(n);
	}

	return 0;
}
