#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<char, int>P;

int main(){
	int b[5];
	while (cin >> b[0], b[0]) {
		int a[4]{};
		a[b[0]] = true;
		for (int i = 1; i < 5; i++) {
			cin >> b[i]; a[b[i]] = true;
		}
		int cnt = 0;
		for (int i = 1; i <= 3; i++)if (a[i])cnt++;
		if (cnt == 1 || cnt == 3) {
			rep(i, 5)puts("3");
			continue;
		}
		int m; for (int i = 1; i <= 3; i++)if (!a[i])m = i;
		int k;
		switch (m) {
		case 1:k = 2; break;
		case 2:k = 3; break;
		case 3:k = 1; break;
		}
		rep(i, 5) {
			if (b[i] == k)puts("1");
			else puts("2");
		}
	}
	return 0;
}