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>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

int main(){

	int data;
	while(cin>>data&&data!=0){
		vector<int> d;
		set<int> s;
		s.insert(data);
		d.push_back(data);
		for(int i = 0; i < 4; i++){
			int t;
			cin>>t;
			s.insert(t);
			d.push_back(t);
		}
		if(s.size()==3||s.size()==1){
			for(int i = 0; i < 5; i++){
				cout<<3<<endl;
			}
		}
		else{
			bool f[4];
			f[0]=f[3]=f[1]=f[2]=false;
			for(set<int>::iterator it = s.begin(); it!=s.end();it++){
				f[*it]=true;
			}
			if(!f[3]){
				for(int i = 0; i < 5; i++){
					if(d[i]==1){
						cout<<1<<endl;
					}
					else
						cout<<2<<endl;
				}
			}
			else if(!f[1]){
				for(int i = 0; i < 5; i++){
					if(d[i]==2){
						cout<<1<<endl;
					}
					else
						cout<<2<<endl;
				}
			}
			else if(!f[2]){
				for(int i = 0; i < 5; i++){
					if(d[i]==3){
						cout<<1<<endl;
					}
					else
						cout<<2<<endl;
				}
			}
		}
	}

	return 0;
}

C++: #include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    int a[5];
    while(cin>>a[0]){
        if(a[0]==0)break;
        for(int i=1;i<5;i++){
            cin>>a[i];
        }
        
        rep(i,5){
            bool win=true;
            bool lose=true;
            rep(j,5){
                if(i!=j){
                    if(a[j]==(a[i]+1)%3+1)win=false;
                    if(a[j]==(a[i])%3+1)lose=false;
                }
            }
            bool ai=true;
            for(int i=1;i<5;i++){
                if(a[i]!=a[i-1])ai=false;
            }
            if( (!win && !lose) || ai){
                cout<<"3"<<endl;
            }
            else if(win)cout<<"1"<<endl;
            else if(lose)cout<<"2"<<endl;

        }
        
    }
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;



int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };

int A = 0, B = 0, K = 0, T = 0, W = 0, N = 0, H = 0;
int n = 0;
double L = 0;
double S = 0;
double ar = 0, br = 0, cr = 0;
int answer = 0;

string C;
string sA, strB;
vector<vector<char>> map;
vector<int> card;
vector<string> str;

int sum = 0;


void input() {

	while (true) {
		CI n;
		if (n == 0) {
			break;
		}
		card.push_back(n);
	}

	return;
}


int main(void) {
	int goo = 0;
	int choki = 0;
	int paa = 0;
	input();

	REP(i, card.size() / 5) {
		for (int j = (i * 5); j < (i * 5) + 5; j++) {
			switch (card[j]) {
			case 1:
				goo++;
				break;
			case 2:
				choki++;
				break;
			case 3:
				paa++;
				break;
			default:
				break;
			}
		}
		if ((goo > 0 && choki > 0 && paa > 0) || goo == 5 || paa == 5 || choki == 5) {
			REP(j, 5)CO 3 E
		}
		else {
			if (goo > 0 && choki > 0 && paa <= 0) {
				for (int j = i * 5; j < (i * 5) + 5; j++) {
					switch (card[j]) {
					case 1:
						CO 1 E
							break;
					case 2:
						CO 2 E
							break;
					default:
						break;
					}
				}
			}
			if (goo <= 0 && choki > 0 && paa > 0) {
				for (int j = i * 5; j < (i * 5) + 5; j++) {
					switch (card[j]) {
					case 1:
						break;
					case 2:
						CO 1 E
							break;
					case 3:
						CO 2 E
							break;
					default:
						break;
					}
				}
			}
			if (goo > 0 && choki <= 0 && paa > 0) {
				for (int j = i * 5; j < (i * 5) + 5; j++) {
					switch (card[j]) {
					case 1:
						CO 2 E
						break;
					case 2:
						break;
					case 3:
						CO 1 E
						break;
					default:
						break;
					}
				}
			}
			

		}
		goo = 0;
		choki = 0;
		paa = 0;
	}


	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

int main(){
    while(true){
        vector<int> te(3);
        vector<int> per(5);
        for(int i=0;i<5;i++){
            int x;
            cin >> x;
            x--;
            if(x == -1) return 0;
            te[x]++;
            per[i] = x;

        }
        if(*min_element(all(te)) > 0){
            for(int i=0;i<5;i++){
                cout << 3 << endl;
            }
        }else{
            vector<char> win(5);
            if(te[0] > 0 and te[1] > 0){
                for(int i=0;i<5;i++){
                    if(per[i] == 0) win[i] = true;
                }
            }
            if(te[1] > 0 and te[2] > 0){
                for(int i=0;i<5;i++){
                    if(per[i] == 1) win[i] = true;
                }
            }
            if(te[2] > 0 and te[0] > 0){
                for(int i=0;i<5;i++){
                    if(per[i] == 2) win[i] = true;
                }
            }
            for(int i=0;i<5;i++){
                if(win[i]){
                    cout << 1 << endl;
                }else{
                    cout << 2 << endl;
                }
            }
        }
    }
    return 0;
}