#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int n, l[30];

void solve() {
  int rest = 32, ptr = 0;
  while (rest) {
    rest -= (rest - 1) % 5;
    cout << rest << endl;
    if (rest > l[ptr]) {
      rest -= l[ptr];
      ptr++;
      if (ptr >= n) ptr = 0;
    } else {
      rest = 0;
    }
    cout << rest << endl;
  }
}

int main() {
  while (cin >> n, n) {
    rep (i,n) {
      cin >> l[i];
    }
    solve();
  }
}