#include<iostream>

#define MAX_LEN 32
using namespace std;

int main(){
	while(true){
		int i;
		int now = 0;
		int yama = 32;
		int jiro[MAX_LEN]={0,};
		scanf("%d", &i);
		if(i==0)break;
		for(int t = 0; t < i; ++t){
			scanf("%d", &jiro[t]);
		}
		while( yama > 0 ){
			yama -= ( yama - 1 ) % 5;
			printf("%d\n", yama);
			yama -= std::min( yama, jiro[now] );
			printf("%d\n", yama);
			++now;
			if(now>=i)now=0;
		}
	}
	return 0;
}