#include <iostream>
#include <vector>
using namespace std;

int main() {
  while(true) {
    vector<int> jiros;
    int n;
    cin >> n;
    if(n == 0) break;
    for(int i = 0; i < n; ++i) {
      int num;
      cin >> num;
      jiros.push_back(num);
    }
    int left = 32;
    for(int i = 0; ; ++i) {
      left -= (left - 1) % 5;
      if(left <= 0) {cout << 0 << endl;break;}
      cout << left << endl;
      left -= jiros[i % n];
      if(left <= 0) {cout << 0 << endl;break;}
      cout << left << endl;
    }
  }
  return 0;
}