#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define f first
#define s second

main(){
  int n;
  while(cin>>n,n){
    int re[n];
    rep(i,n)cin>>re[i];
    int oh=32;
    bool ban=true;
    int ji=0;
    while(oh){
      if(ban){
        oh-=(oh+4)%5;
        cout<<oh<<endl;
      }else{
        oh-=re[ji++%n];
        if(oh<0)oh=0;
        cout<<oh<<endl;
      }
      ban=!ban;
    }
  }
}