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

int main() {
    for(int len; cin >> len, len; ) {
        vector<int> arr(len);
        for(int i = 0; i < len; i++) cin >> arr[i];
        int a = 0;
        int num = 32;
        num -= (num - 1) % 5;
        cout << num << endl;
        while(num >= 0) {
            if(arr[a] >= num) {
                cout << 0 << endl;
                break;
            }
            num -= arr[a];
            cout << num << endl;
            num -= (num - 1) % 5;
            cout << num << endl;
            a = (a + 1) % arr.size();
        }
    }
}