#include <iostream>

using namespace std;

int main()
{
	int n, a[4], s, t, p;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> a[i];
		}
		s = 32;
		p = 0;
		while(s > 0){
			t = (s-1)%5;
			s -= t;
			cout << s << endl;
			
			s -= a[p%n];
			p++;
			if(s < 0){
				s = 0;
			}
			cout << s << endl;
		}
	}
	
	return 0;
}