#include <iostream>
using namespace std;
int main()
{
	int n, m, a[25], i;
	while (cin >> m && m)
	{
		for (i = 0; i < m; i++)
			cin >> a[i];
		n = 32;
		i = 0;
		while (n > 0)
		{
			n -= (n-1)%5;
			cout << n << endl;
			if (n <= 0) break;
			n -= ((a[i]>=n)?n:a[i]);
			cout << n << endl;
			i++;
			if (i >= m) i = 0;
		}
	}
}