#include <iostream>

using namespace std;

void loop(int remain, int* jiro_rule, int rule_size, int cur) {
    remain -= (remain - 1) % 5;
    cout << remain << endl;
    if (remain == 0) return;
    if (remain <= *(jiro_rule + cur)) {
        cout << 0 << endl;
        return;
    }
    remain -= *(jiro_rule + cur);
    cout << remain << endl;
    cur++;
    if (cur == rule_size) cur = 0;
    loop(remain, jiro_rule, rule_size, cur);
}

int main() {
    int i;
    while (cin >> i) {
        if (i == 0) break;
        int a[i];
        for (int p = 0; p < i; p++) {
            cin >> a[p];
        }
        loop(32, a, i, 0);
    }
    return 0;
}