#include<iostream>
#include<algorithm>
using namespace std;


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