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 <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
    int a[5];
    while(1){
        cin>>a[0];
        if(a[0]==0) break;
        rep(i,4) cin>>a[i+1];
        vint v(5);
        rep(i,5){
            v[i]=a[i];
        }
        sort(ALL(v));
        if(v[0]==v[4]){
            rep(i,5){
                cout<<3<<endl;
            }
            continue;
        }
        bool f=false;
        rep(i,5){
            if(v[i]==2) f=true;
        }
        if(f&&v[0]==1&&v[4]==3){
            rep(i,5){
                cout<<3<<endl;
            }
            continue;
        }
        int b[]={2,3,1};
        reep(i,1,4){
            bool f=true;
            rep(j,5){
                if(a[j]==i) f=false;
            }
            if(f){
                rep(j,5){
                    if(a[j]==b[i-1]) cout<<1<<endl;
                    else cout<<2<<endl;
                }
                break;
            }
        }
    }
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
      cout<<fixed<<setprecision(20);
    mainmain();
}

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int main() {
	int h[5], cnt[4];
	
	while (cin >> h[0], h[0]) {
		FOR(i, 1, 5) cin >> h[i];
		
		memset(cnt, 0, sizeof(cnt));
		REP(i, 5) cnt[h[i]]++;
		
		int ans[5];
		int win = -1, lose = -1, draw = 0;
		
		int zero = 0;
		FOR(i, 1, 4) if (cnt[i] > 0) draw++;
		if (draw == 1) draw = 3;
		
		if (draw == 3) {
			REP(i, 5) ans[i] = 3;
		}
		else {
			if (cnt[1] > 0 && cnt[2] > 0) win = 1;
			if (cnt[2] > 0 && cnt[3] > 0) win = 2;
			if (cnt[3] > 0 && cnt[1] > 0) win = 3;			
			REP(i, 5) {
				if (h[i] == win) ans[i] = 1;
				else ans[i] = 2;
			}
		}
		
		REP(i, 5) printf("%d\n", ans[i]);
		
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
  int N;cin>>N;
  while(N>0) {
    int a[5],v[5],b=0,f=0;
    for(;b<5;++b) {
      a[N]++;v[b]=N;f|=1<<--N;cin>>N;
    }
    f=f%7*7%4;
    b=0;
    if(!f) for(;b<5;++b) cout<<3<<endl;
    else for(;b<5;++b) cout<<((v[b]==f)?1:2)<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;


int one[5];
int te[5];
int han[3];

main(){
	int n;
	
	while(cin>>n){
		if(n==0)break;
		
		for(int i=0;i<5;i++){
			one[i]=te[i]=0;
		}
		
		one[0]=n;
		++te[n];
		
		for(int i=1;i<5;i++){
			cin>>n;
			one[i]=n;
			++te[n];
		}
		
		int hiki=0;
		for(int i=1;i<=3;i++){
			if(te[i]==5)hiki+=10;
		}
		
		for(int i=1;i<=3;i++){
			if(te[i])++hiki;
		}
		
		if(hiki/10 || hiki%10==3){
			for(int i=0;i<5;i++){
				puts("3");
			}
			continue;
		}
		
		if(te[1]==0){
			han[1]=3;
			han[2]=1;
			han[3]=2;
		}else if(te[2]==0){
			han[1]=2;
			han[2]=3;
			han[3]=1;
		}else{
			han[1]=1;
			han[2]=2;
			han[3]=3;
		}
		
		for(int i=0;i<5;i++){
			printf("%d\n",han[one[i]]);
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>

using namespace std;

int main() {
    while(true) {
        vector<int> v(5, 0);
        vector<int> cnt(3, 0);
        for(int i = 0; i < 5; ++i) {
            cin >> v[i];
            if(v[i] == 0) return 0;
            v[i]--;
            cnt[v[i]]++;
        }

        if((cnt[0] > 0 && cnt[1] > 0 && cnt[2] > 0) || cnt[0] == 5 || cnt[1] == 5 || cnt[2] == 5) {
            for(int i = 0; i < 5; ++i) v[i] = 3;
        }
        else {
            for(int i = 0; i < 5; ++i) v[i] = cnt[(v[i]+1)%3]>0 ? 1 : 2;
        }

        for(int i = 0; i < 5; ++i) cout << v[i] << endl;
    }
    return 0;
}