#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int n;
  while (cin >> n, n) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }

    int rest = 32, i = 0, j = 0;
    while (rest) {
      int sub;
      if (i % 2) {
        rest -= min(rest, a[j++ % n]);
      } else {
        rest -= min(rest, (rest - 1) % 5);
      }
      cout << rest << endl;
      i++;
    }
  }
  
  return 0;
}
