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++: // Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int t[5];
		cin >> t[0];

		if(t[0]==0)
			break;

		for(int i=1; i<5; i++){
			cin >> t[i];
		}

		int s[4] = {0};
		for(int i=0; i<5; i++){
			s[t[i]]++;
		}

		int r[5];
		if((s[2]==0&&s[3]==0)
		 ||(s[3]==0&&s[1]==0)
		 ||(s[1]==0&&s[2]==0)
		 ||(s[1]!=0&&s[2]!=0&&s[3]!=0)){
			for(int i=0; i<5; i++){
				r[i] = 3;
			}
		}
		else if(s[3]==0){
			for(int i=0; i<5; i++){
				if(t[i]==1){
					r[i] = 1;
				}
				else{
					r[i] = 2;
				}
			}
		}
		else if(s[1]==0){
			for(int i=0; i<5; i++){
				if(t[i]==2){
					r[i] = 1;
				}
				else{
					r[i] = 2;
				}
			}
		}
		else if(s[2]==0){
			for(int i=0; i<5; i++){
				if(t[i]==3){
					r[i] = 1;
				}
				else{
					r[i] = 2;
				}
			}
		}

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

	return 0;
}

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

using namespace std;

set<int> con;
vector<int> lcon;

int main(int argc, char* argv[])
{
	int c0, c1, c2, c3, c4;
	
	while(1) {

		cin >> c0;
		if( c0 == 0 )
			break;
		
		cin >> c1 >> c2 >> c3 >> c4;

		con.insert(c0);	lcon.push_back(c0);
		con.insert(c1);	lcon.push_back(c1);
		con.insert(c2);	lcon.push_back(c2);
		con.insert(c3);	lcon.push_back(c3);
		con.insert(c4);	lcon.push_back(c4);

		for( auto c : lcon ) {

			int o0 = c%3 + 1;
			int o1 = (c+1)%3 + 1;

			bool f0 = ( con.find(o0) != con.end() );
			bool f1 = ( con.find(o1) != con.end() );

			if( !f0 && f1 ) cout << 2 << endl;			
			else if( f0 && !f1 ) cout << 1 << endl;
			else if( f0 && f1 ) cout << 3 << endl;
		}

		con.clear();
		lcon.clear();
	}

    return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  vi v(5);
  while (cin >> v[0], v[0]) {
    loop(i, 1, 5) cin >> v[i];
    vi w(4);
    rep(i, 5) {
      v[i]--;
      w[v[i]]++;
      if (v[i] == 0) w[3]++;
    }
    if (w[0] > 0 && w[1] > 0 && w[2] > 0) {
      rep(i, 5) cout << 3 << endl;
      continue;
    }
    rep(i, 5) {
      cout << 2 - !!w[v[i] + 1] << endl;
    }
  }
}

C++: #include<stdio.h>
bool table[3];
int main(){
	int a,b,c,d,e;
	while(scanf("%d",&a),a){
		table[0]=table[1]=table[2]=false;
		scanf("%d%d%d%d",&b,&c,&d,&e);
		table[a-1]=true;
		table[b-1]=true;
		table[c-1]=true;
		table[d-1]=true;
		table[e-1]=true;
		bool aiko=false;
		if(table[0]&&table[1]&&table[2])aiko=true;
		if(a==b&&b==c&&c==d&&d==e)aiko=true;
		if(aiko)printf("3\n3\n3\n3\n3\n");
		else{
			int in[]={a,b,c,d,e};
			int win;
			if(!table[0])win=2;
			if(!table[1])win=3;
			if(!table[2])win=1;
			for(int i=0;i<5;i++)printf(in[i]==win?"1\n":"2\n");
		}
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  int h[5],cnt[3],ans[5];
  
  while(cin >> h[0],h[0]!=0){
    for(int i=1;i<5;i++) cin >> h[i];
    
    cnt[1] = 0;
    cnt[2] = 0;
    cnt[3] = 0;
    
    for(int i=0;i<5;i++) cnt[ h[i] ]++;
    
    for(int i=0;i<5;i++){
      if(cnt[1] == 5 || cnt[2] == 5 || cnt[1]+cnt[2] == 0) cout << 3 << endl;
      else if(cnt[1] != 0 && cnt[2] != 0 && cnt[3] != 0) cout << 3 << endl;
      else if(cnt[1] == 0){
	if(h[i] == 2) cout << 1 << endl;
	else cout << 2 << endl;
      }
      else if(cnt[2] == 0){
	if(h[i] == 3) cout << 1 << endl;
	else cout << 2 << endl;
      }
      else if(cnt[3] == 0){
	if(h[i] == 1) cout << 1 << endl;
	else cout << 2 << endl;
      }
    }

  }
  return(0);
}

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

int main() {
  int a[5];
  while(cin >> a[0] && a[0]) {
    for(int i=1; i<5; i++) cin >> a[i];
    for(int i=0; i<5; i++) {
      int win = 0, lose = 0;
      for(int j=0; j<5; j++) {
	if(a[i]%3 == a[j]-1) win ++;
	if(a[j]%3 == a[i]-1) lose ++;
      }
      int res;
      if(win && lose == 0) res = 1;
      else if(win == 0 && lose) res = 2;
      else res = 3;
      cout << res << endl;
    }
  }
  
  return 0;
}

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

int main(){
  int h[5];
  int g,c,p;
  int a[5];

  while(1){
    cin >> h[0];
    if(!h[0])break;

    for(int i=1;i<5;i++)cin >> h[i];
    g = 0;
    c = 0;
    p = 0;
    for(int i=0;i<5;i++){
      if(h[i] == 1)g++;
      if(h[i] == 2)c++;
      if(h[i] == 3)p++;
    }

    if(g>0 && c>0 && p>0){
      for(int i=0;i<5;i++)a[i] = 3;
    }else if(g==5 || c==5 || p==5){
      for(int i=0;i<5;i++)a[i] = 3;
    }else{
      if(g>0 && c>0){
	for(int i=0;i<5;i++){
	  if(h[i] == 1)a[i] = 1;
	  if(h[i] == 2)a[i] = 2;
	}
      }
      if(c>0 && p>0){
	for(int i=0;i<5;i++){
	  if(h[i] == 2)a[i] = 1;
	  if(h[i] == 3)a[i] = 2;
	}
      }
      if(p>0 && g>0){
	for(int i=0;i<5;i++){
	  if(h[i] == 3)a[i] = 1;
	  if(h[i] == 1)a[i] = 2;
	}
      }
    }
    for(int i=0;i<5;i++)cout << a[i] <<endl;
  }
}

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

int main() 
{
	while (1) {
		int a, b, c, d, e;
		cin >> a;
		if (a == 0)break;
		cin >> b >> c >> d >> e;
		if (a==b&&b==c&&c==d&&d==e) { cout << "3\n3\n3\n3\n3\n"; continue; }
		vector<int>f(5);
		vector<int>q(5);
		f[0] = a;
		f[1] = b;
		f[2] = c;
		f[3] = d;
		f[4] = e;
		q[0] = a;
		q[1] = b;
		q[2] = c;
		q[3] = d;
		q[4] = e;
		sort(f.begin(), f.end());
		if(f[0]==1&&(f[1]==2||f[2]==2||f[3]==2)&&f[4]==3){cout<<"3\n3\n3\n3\n3\n"; continue;}
		if (f[0] == 2) {
			for (int i = 0; i < 5; i++) {
				if (q[i] == 2)cout << 1 << endl;
				else cout << 2 << endl;
			}
			continue;
		}
		if (f[4] == 3) {
			for (int i = 0; i < 5; i++) {
				if (q[i] == 3)cout << 1 << endl;
				else cout << 2 << endl;
			}
			continue;
		}
		else {
			for (int i = 0; i < 5; i++) {
				if (q[i] == 1)cout << 1 << endl;
				else cout << 2 << endl;
			}
			continue;
		}
	}
}