#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

using namespace std;

int main()
{
	int h[5];
	while (cin >> h[0], h[0]) {
		for (int i = 1; i < 5; i++)
			cin >> h[i];

		int g = 0, c = 0, p = 0;
		
		for (int i = 0; i < 5; i++) {
			if (h[i] == 1)g++;
			if (h[i] == 2)c++;
			if (h[i] == 3)p++;
		}
		if ((g != 0 && c != 0 && p != 0)||
			g == 5 || c == 5 || p == 5) {
			for (int i = 0; i < 5; i++)
				cout << 3 << endl;
		}else{
			if (p == 0) {
				for (int i = 0; i < 5; i++)
					cout << (h[i] == 1 ? 1 : 2 )<< endl;
			}
			if (g == 0) {
				for (int i = 0; i < 5; i++)
					cout << (h[i] == 2 ? 1 : 2) << endl;
			}
			if (c == 0) {
				for (int i = 0; i < 5; i++)
					cout << (h[i] == 3 ? 1 : 2) << endl;
			}
		}
	}
	return	0; 
}