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

int main() {
    int n;
    while (cin >> n, n) {
        vector<int> a(n);
        for (int i=0; i<n; ++i) {
            cin >> a[i];
        }
        int x = 32;
        int k = 0;
        while (x) {
            x = max(0, x - (x - 1) % 5);
            cout << x << endl;
            if ( ! x) break;
            x = max(0, x - a[k]);
            cout << x << endl;
            k = (k + 1) % n;
        }
    }
    return 0;
}