#include<iostream>
#include<string>
using namespace std;
int main(){
	int m,n[100];
	while(true){
	cin>>m;
	if(m==0)
		break;
	for(int i=0;i<m;i++)
		cin>>n[i];
	int ans=31;
	int count=0;
	cout<<"31"<<endl;
	while(true){
		if(ans<=n[count]){
			cout<<"0"<<endl;
			break;
		}
		ans-=n[count];
		cout<<ans<<endl;
		ans-=(ans-1)%5;
		cout<<ans<<endl;
		count++;
		count%=m;
	}
	}
	return 0;
}