Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		h := make([]int, 5)
		h[0], _ = strconv.Atoi(scanner.Text())
		if h[0] == 0 {
			break
		}
		for i := 1; i <= 4; i++ {
			scanner.Scan()
			h[i], _ = strconv.Atoi(scanner.Text())
		}
		tbl := make([]bool, 3)
		aiko := false
		for _, v := range h {
			tbl[v-1] = true
		}
		if tbl[0] && tbl[1] && tbl[2] { // 全ての手があるあいこ
			aiko = true
		}
		if h[0] == h[1] && h[1] == h[2] && h[2] == h[3] && h[3] == h[4] {
			aiko = true
		}
		if aiko {
			fmt.Printf("3\n3\n3\n3\n3\n")
		} else {
			win := 0
			if !tbl[0] {
				win = 2
			}
			if !tbl[1] {
				win = 3
			}
			if !tbl[2] {
				win = 1
			}
			for i := 0; i < 5; i++ {
				if h[i] == win {
					fmt.Println(1)
				} else {
					fmt.Println(2)
				}
			}
		}
	}
}

C++: #include<iostream>
using namespace std;
int main() {
	int n;
	int out[4] = { false };
	while (cin >> n&&n != 0) {
		int line[5];
		bool used[4] = { false };
		int count = 1;
		used[n] = true;
		line[0] = n;
		for (int i = 1; i < 5; ++i) {
			cin >> line[i];
			if (used[line[i]] == false)++count;
			used[line[i]] = true;
		}
		if (count == 3 || count == 1) {
			for(int i=0;i<5;++i)
			cout << 3 << endl;
		}
		else {
			if (used[1] == false) {
				out[2] = 1;
				out[3] = 2;
			}
			else if (used[2] == false) {
				out[1] = 2;
				out[3] = 1;
			}
			else {
				out[1] = 1;
				out[2] = 2;
			}
			for (int i = 0; i < 5; ++i) {
				cout << out[line[i]] << endl;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#define rep(n) for(int i=0;i<(n);i++)
using namespace std;

int main(void){
	int a[5];
	while(cin>>a[0],a[0]){
		cin>>a[1]>>a[2]>>a[3]>>a[4];
		int b[4];
		b[1]=0;
		b[2]=0;
		b[3]=0;
		rep(5)b[a[i]]++;
		if(b[1]>0&&b[2]>0&&b[3]>0||b[1]==5||b[2]==5||b[3]==5){
			rep(5) cout<<3<<endl;
			continue;
		}
		if(b[1]&&b[2]){
			rep(5){
				if(a[i]==1)cout<<"1"<<endl;
				else cout<<"2"<<endl;
			}
		}else if(b[2]&&b[3]){
			rep(5){
				if(a[i]==2)cout<<"1"<<endl;
				else cout<<"2"<<endl;
			}
		}else if(b[3]&&b[1]){
			rep(5){
				if(a[i]==3)cout<<"1"<<endl;
				else cout<<"2"<<endl;
			}
		}
	}
	return 0;
}

C++: // #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 10????????? cout << setprecision(10) << double;
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (???test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// ??\??????push_back(d)???array[d]???????????????1?????§?????????
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN(){T d;cin>>d;return d;}
// ?????§??¬?´???°???Greatest Common Divisor???
LL gcd(LL a, LL b){ return (b > 0) ? gcd(b, a%b) : a; }
// ????°???¬?????°???Least Common Multiple???
LL lcm(LL a, LL b){ return a / gcd(a, b) * b; }

// ------------------- include, typedef, define END. -------------------

// return 0:aiko , 1:win g , 2:win c 3: win p
int Result(bool demashita[]){

	// aiko : 5?????¨???????????????or  3?¨??????¨??¨??????
	if( (!demashita[0] && !demashita[1]) ||
		(!demashita[1] && !demashita[2]) ||
		(!demashita[2] && !demashita[0]) ||
		(demashita[0] && demashita[1] && demashita[2]))
		return 0;

	// ????????????
	else if(!demashita[2])	return 1;
	// ?????§?????????
	else if(!demashita[1])	return 3;
	// ??°?????????
	else return 2;

	return 0;
}

void Output(int hand[], int result){
	FOR(i,0,5){
		int ans=0;
		if(result == 1){
			// ??°?????????
			if(hand[i] == 1)	ans = 1;
			else				ans = 2;
		}else if(result == 2){
			// ?????§?????????
			if(hand[i] == 2)	ans = 1;
			else				ans = 2;
		}else if(result == 3){
			// ????????????
			if(hand[i] == 3)	ans = 1;
			else				ans = 2;
		}else{
			// ?????????
			ans = 3;
		}
		cout << ans << endl;
	}
}

int main(){
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;
	
	//??????????????????????????????.
	int hand[5];
	while(cin>>hand[0],hand[0]){
		bool demashita[3] = {false,false,false};	// [0]:g [1]:c [2]:p
		FOR(i,0,4){
			cin >> hand[i+1];
			demashita[ hand[i+1] - 1 ] = true;
		}
		// output ans
		Output(hand, Result(demashita));
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;

















































































































































































































































































































































































































































































































































































































































int main()
{
	for(;;){
		int a;
		int b;
		int c;
		int d;
		int e;
		cin >> a;
		if(a==0)break;
		cin >> b >> c >> d >> e;
		int x1=0;
		int x2=0;
		int x3=0;
		if(a==1)x1++;
		if(a==2)x2++;
        if(a==3)x3++;
		if(b==1)x1++;
		if(b==2)x2++;
        if(b==3)x3++;
		if(c==1)x1++;
		if(c==2)x2++;
        if(c==3)x3++;
		if(d==1)x1++;
		if(d==2)x2++;
        if(d==3)x3++;
		if(e==1)x1++;
		if(e==2)x2++;
        if(e==3)x3++;
		if(x1>=1&&x2>=1&&x3>=1){
			printf("3\n3\n3\n3\n3\n");
		}
		else if(x1==5){
			printf("3\n3\n3\n3\n3\n");
		}
		else if(x2==5){
			printf("3\n3\n3\n3\n3\n");
		}
		else if(x3==5){
			printf("3\n3\n3\n3\n3\n");
		}
		else if(x3==0){
			if(a==1)printf("1\n");
			if(a==2)printf("2\n");
			if(b==1)printf("1\n");
			if(b==2)printf("2\n");
			if(c==1)printf("1\n");
			if(c==2)printf("2\n");
			if(d==1)printf("1\n");
			if(d==2)printf("2\n");
			if(e==1)printf("1\n");
			if(e==2)printf("2\n");
		}
		else if(x2==0){
			if(a==3)printf("1\n");
			if(a==1)printf("2\n");
			if(b==3)printf("1\n");
			if(b==1)printf("2\n");
			if(c==3)printf("1\n");
			if(c==1)printf("2\n");
			if(d==3)printf("1\n");
			if(d==1)printf("2\n");
			if(e==3)printf("1\n");
			if(e==1)printf("2\n");
		}
		else if(x1==0){
			if(a==2)printf("1\n");
			if(a==3)printf("2\n");
			if(b==2)printf("1\n");
			if(b==3)printf("2\n");
			if(c==2)printf("1\n");
			if(c==3)printf("2\n");
			if(d==2)printf("1\n");
			if(d==3)printf("2\n");
			if(e==2)printf("1\n");
			if(e==3)printf("2\n");
		}
	}
	return 0;
}