#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		int a[25];
		for (int i = 0; i < n; ++i)
			scanf("%d", a+i);

		int left = 32;
		for (int i = 0; left; ++i)
		{
			if (i & 1)
				left -= min(left, a[(i/2) % n]);
			else
				left -= (left - 1) % 5;
			printf("%d\n", left);
		}
	}

	return 0;
}