#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	int l;
	while (cin >> l, l) {
		vector<int> num(l);
		REP(i, l) cin >> num[i];
		
		int now = 32, pos = 0;
		bool itiro = true;
		
		while (now > 0) {
			if (itiro) now -= (now - 1) % 5;
			else {
				now -= num[pos++];
				pos %= l;
			}
			if (now > 0) cout << now << endl;
			else puts("0");
			itiro = !itiro;
		}
	}
	return 0;
}