#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  int n;
  int a[33];
  while(cin >> n){
    if(!n) break;
    for(int i = 0; i < n; i++){
      cin >> a[i];
    }
    int p = 32;
    for(int i = 0;p; i++){
      if(i%2){
	p -= a[i/2%n];
      }else{
	p -= (p-1)%5;
      }
      p = max(0,p);
      cout << p << endl;
    }
  }
}