#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
    while(1){
        int r=32;
        int i;
        int a[1000];
        cin>>i;
        if(i==0)break;
        for(int j=0;j<i;j++){
            cin>>a[j];
        }
        int k=0;
        for(int j=0;r>0;j++){
            if(j%2==0)r-=(r-1)%5;
            else if(j%2==1)r-=a[k],k++;
            if(k==i)k=0;
            if(r>0)cout<<r<<endl;
            else cout<<0<<endl;
        }
    }
	return 0;
}