#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define bitcount(b) __builtin_popcount(b)

int main(){
	int hand[5];
	while(1){
		int bit = 0;
		rep(i,5){
			if(cin >> hand[i])bit |= 1 << (--hand[i]) ;
			else  return 0;
		}
		if( bitcount(bit) != 2){
			rep(i,5) cout << 3 << endl;
		}else{
			rep(i,5) cout << 1 + !count( hand , hand+5 , (hand[i]+1)%3 ) << endl;
		}
	}
}