#include <iostream>
#include <vector>

using namespace std;

void saiki(vector<int> &v,int ind,int rest){
    if(ind >= v.size()){
        ind = 0;
    }
    rest -= (rest-1) % 5;
    cout << rest << endl;
    if(rest <= v[ind]){
        cout << 0 << endl;
        return;
    }
    rest -= v[ind];
    cout << rest << endl;

    ind++;
    saiki(v,ind,rest);
}
void solve(vector<int> nexts){
    saiki(nexts,0,32);
}

int main(){
    int n = 0;
    while(cin >> n && n!=0){
        vector<int> nexts;
        for(int i=0;i<n;i++){
            int x;
            cin >> x;
            nexts.push_back(x);
        }
        solve(nexts);
    }
}