#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
	int n;

	while (cin >> n, n){
		vector<int> v;
		for (int i = 0; i < n; i++){
			int t;
			cin >> t;
			v.push_back(t);
		}

		int total = 32;
		int i = 0;
		while (total){
			total -= (total - 1) % 5;
			cout << total << endl;
			total = fmax(total - v[i % n], 0);
			cout << total << endl;
			i++;
		}
	}

	return 0;
}