#include <iostream>
using namespace std;

int main(){
	int n,a[25],i,b,c,on;
	while(cin >> n && n){
		for(i = 0;i < n;i++){
			cin >> b;
			a[i] = b;
		}
		b = c = 0;
		on = 32;
		while(1){
			on -= ((on - 1) % 5);
			cout << on << endl;

			if(a[c] < on) {
				on -= a[c];
				cout << on << endl;
			}
			else {
				on = 0;
				cout << on << endl;
			}
			c++;
			if(c == n) c = 0;
			if(on == 0) break;
		}
	}
	return 0;
}