#include<iostream>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		int a[25];
		for (int i = 0; i < n; i++)
			cin >> a[i];
		int b = 0,c=32;
		while (c > 0) {
			c -= ((c-1) % 5);
			cout << c << endl;
			if (c < a[b]) {
				cout << 0 << endl;
				c = 0;
				break;
			}
			c -= a[b];
			b++;
			if (b >= n) b = 0;
			cout << c<<endl;
		}
	}
}