#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;


int main()
{
    int N;
    while(cin >> N, N){
        int n;
        vector<int> ns{};
        for(int i=0;i<N;++i) { cin >> n; ns.push_back(n); }
        
        int rem = 32, idx = 0;
        while(rem){
            rem -= (rem - 1) % 5;
            cout << rem << endl;
            rem -= min(ns[idx % N], rem);
            cout << rem << endl;
            ++idx;
        }
    }
}