#include<iostream>
using namespace std;
int main(){
long i,j,a[25],r;
while(cin>>i){
if(i==0)break;
for(j=0;j<i;j++)cin>>a[j];
r=31;
cout<<r<<endl;
for(j=0;;j++){
if(j==i)j=0;
r-=a[j];
cout<<r<<endl;
r=(r-1)/5*5+1;
cout<<r<<endl;
if(r==1)break;
}
cout<<'0'<<endl;
}
return 0;
}