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++: // #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
		demashita[ hand[0] - 1 ] = true;
		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<set>
using namespace std;

int main(){
    while(1){
        int A[5];

        cin >> A[0];
        if(A[0] == 0)   break;

        set<int> appear;
        appear.insert(A[0]);
        for(int i = 1; i < 5; i++){
            cin >> A[i];
            appear.insert(A[i]);
        }

        if(appear.size() != 2){
            for(int i = 0; i < 5; i++)  cout << 3 << endl;
        }else{
            int win, lose;
            bool b[4] = {};
            for(int x : appear) b[x] = true;
            if(b[1] && b[2]){
                win = 1;
                lose = 2;
            }else if(b[2] && b[3]){
                win = 2;
                lose = 3;
            }else if(b[3] && b[1]){
                win = 3;
                lose = 1;
            }

            for(int i = 0; i < 5; i++){
                if(A[i] == win)         cout << 1 << endl;
                else if(A[i] == lose)   cout << 2 << endl;
            }
        }
    }
    return 0;
}

C++: #include <iostream>
#define rep(i) for(i=0;i<5;i++)
using namespace std;
int main(){
  int n,a[5],i;
  while(cin>>a[0],a[0]){
    int b[3]={0};
    b[a[i]-1]++;
    for(i=1;i<5;i++){
      cin>>a[i];
      b[a[i]-1]++;
    }
    if(b[0]&&b[1]&&!b[2])rep(i)cout<<((a[i]==1)?1:2)<<endl;
    else if(b[0]&&!b[1]&&b[2])rep(i)cout<<((a[i]==3)?1:2)<<endl;
    else if(!b[0]&&b[1]&&b[2])rep(i)cout<<((a[i]==2)?1:2)<<endl;
    else rep(i)cout<<'3'<<endl;
  }
}

C++: i,f,d[5],*p;main(n){for(;i>4||scanf("%d",p=d+i)**d;i=++i%10,f*=!!i)n=((f^f/2^f/4)&1?2:!(d[i%5]*2&f))+49,i<5?f|=(*p=9<<*p-1):puts(&n);}

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

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

C++: #include<bits/stdc++.h>
#define WIN 1
#define LOSE 2
#define DRAW 3
using namespace std;
int main(){
  while(1){
    int p=0,c=0,g=0,finish=0;
    int te[5];
    for(int i=0;i<5;i++){
      cin>>te[i];
      if(te[i]==0){
	finish=1;
	break;
      }
      switch(te[i]){
      case 1:g++;break;
      case 2:c++;break;
      case 3:p++;break;
      }
    }
    if(finish==1)
      break;
    if(g!=0&&c!=0&&p!=0||g==0&&c==0||g==0&&p==0||c==0&&p==0){
      for(int i=0;i<5;i++)
	cout<<DRAW<<endl;
    }else if(g==0){
      for(int i=0;i<5;i++){
	if(te[i]==2)
	  cout<<WIN<<endl;
	else
	  cout<<LOSE<<endl;
      }
    }else if(c==0){
      for(int i=0;i<5;i++){
	if(te[i]==3)
	  cout<<WIN<<endl;
	else
	  cout<<LOSE<<endl;
      }
    }else if(p==0){
      for(int i=0;i<5;i++){
	if(te[i]==1)
	  cout<<WIN<<endl;
	else
	  cout<<LOSE<<endl;
      }
    }
  }
  return 0;
}

C++: #include<stdio.h>

int main(void)
{
  int t[5]={0},t2=0,t3=0,t1=0,k,i;

while(scanf("%d",&k)!=0){

t2=0; t3=0; t1=0;

for(i=0;i<5;i++){
scnaf("%d",&t[i]);
  if(t[i]==1)
       t1++;
else if(t[i]==2)
   t2++;
else if(t[i]==3)
   t3++;
}

if(t1==0){
  if(t2==0 or t3==0) for(i=0;i<5;i++) t[i]=3;
else
   for(i=0;i<5;i++){
       if(t[i]==2)  t[i]=1;
      else if(t[i]==3) t[i]=2;
    }
}
else if(t2==0){
  if(t1==0 or t3==0)   for(i=0;i<5;i++) t[i]=3;
else
   for(i=0;i<5;i++){
       if(t[i]==1)  t[i]=2;
      else if(t[i]==3) t[i]=1;
}
}

else if(t3==0){
  if(t2==0 or t1==0)  for(i=0;i<5;i++) t[i]=3;
else
   for(i=0;i<5;i++){
       if(t[i]==2)  t[i]=2;
      else if(t[i]==1) t[i]=1;
}
}

else   for(i=0;i<5;i++) t[i]=3;
}
for(i=0;i<5;i++)  printf("%d\n",t[i]);

return 0
}