#include<iostream>

using namespace std;
int main(){
  int n;
  while(cin >> n){
    if(n==0) break;
    int p[25],ohajiki=31;
    for(int i=0; i<n; i++) cin >> p[i];
    int count=0;
    cout << ohajiki << endl;
    while(ohajiki!=1){
      if(count == n) count=0;
      ohajiki-=p[count];
      cout << ohajiki << endl;
      count++;
      ohajiki-=(ohajiki-1)%5;
      cout << ohajiki << endl;
    }
    cout << 0 << endl;
  }
  return 0;
}