#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main() 
{
	while (1) {
		int a, b, c, d, e;
		cin >> a;
		if (a == 0)break;
		cin >> b >> c >> d >> e;
		if (a==b&&b==c&&c==d&&d==e) { cout << "3\n3\n3\n3\n3\n"; continue; }
		vector<int>f(5);
		vector<int>q(5);
		f[0] = a;
		f[1] = b;
		f[2] = c;
		f[3] = d;
		f[4] = e;
		q[0] = a;
		q[1] = b;
		q[2] = c;
		q[3] = d;
		q[4] = e;
		sort(f.begin(), f.end());
		if(f[0]==1&&(f[1]==2||f[2]==2||f[3]==2)&&f[4]==3){cout<<"3\n3\n3\n3\n3\n"; continue;}
		if (f[0] == 2) {
			for (int i = 0; i < 5; i++) {
				if (q[i] == 2)cout << 1 << endl;
				else cout << 2 << endl;
			}
			continue;
		}
		if (f[4] == 3) {
			for (int i = 0; i < 5; i++) {
				if (q[i] == 3)cout << 1 << endl;
				else cout << 2 << endl;
			}
			continue;
		}
		else {
			for (int i = 0; i < 5; i++) {
				if (q[i] == 1)cout << 1 << endl;
				else cout << 2 << endl;
			}
			continue;
		}
	}
}