#include <iostream>
using namespace std;

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int* a = new int [n];
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        int i = 0, ohajiki = 32;
        while (ohajiki > 0) {
            ohajiki -= (ohajiki - 1) % 5;
            cout << ohajiki << endl;
            if (ohajiki < a[i]) {
                ohajiki = 0;
            } else {
                ohajiki -= a[i];
            }
            i = (i + 1) % n;
            cout << ohajiki << endl;
        }
    }
}