#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()
{
	while (true)
	{
		int t[5];
		for (int i = 0; i < 5; ++i)
			scanf("%d", t+i);
		if (t[0] == 0)
			break;

		int c[3];
		memset(c, 0, sizeof(c));
		for (int i = 0; i < 5; ++i)
			++c[t[i]-1];
		if (c[0] && c[1] && c[2]
		|| c[0] == 5 || c[1] == 5 || c[2] == 5)
			for (int i = 0; i < 5; ++i)
				puts("3");
		else
			for (int i = 0; i < 5; ++i)
				if (c[(t[i])%3])
					puts("1");
				else
					puts("2");
	}

	return 0;
}