#include <iostream>
using namespace std;

#define repi(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)

int main() {
	ios::sync_with_stdio(false);
	
	int a[5], c[3];
	
	while(1) {
		cin >> a[0];
		if(!a[0])break;
		repi(i, 1, 5) cin >> a[i];
		
		rep(i, 3) c[i] = 0;
		rep(i, 5) c[a[i]-1]++;
		if( (c[0]>0&&c[1]>0&&c[2]>0) || (c[0]==5) || (c[1]==5) || (c[2]==5) ) {
			rep(i, 5)cout << 3 << endl;
		}else if(c[0]==0) {
			rep(i, 5)cout << (a[i]==2?1:2) << endl;
		}else if(c[1]==0) {
			rep(i, 5)cout << (a[i]==3?1:2) << endl;
		}else if(c[2]==0) {
			rep(i, 5)cout << (a[i]==1?1:2) << endl;
		}
	}
	
	return 0;
}