#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int a[5];
	
	while (cin >> a[0], a[0]) {
		for_(i,1,5) cin >> a[i];
		int ex[4] = {0};
		for_(i,0,5) ex[a[i]] = 1;
		int sum = accumulate(ex, ex + 4, int());
		
		
		if (sum == 1 || sum == 3) {
			for_(i,0,5) cout << 3 << endl;
		} else {
			int win = (ex[1] && ex[2]) ? 1 : (ex[2] && ex[3]) ? 2 : 3;
			for_(i,0,5) cout << (a[i] == win ? 1 : 2) << endl;
		}
	}
}