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 <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()


int c[5];
int count_gu;
int count_tyo;
int count_paa;
#define GU 1
#define TYO 2
#define PAA 3

#define WIN 1
#define LOSE 2
#define AIKO 3

void count() {
  count_gu = 0; count_tyo = 0; count_paa = 0;
  rep(i, 5) {
    switch (c[i]) {
      case GU:  count_gu++;  break;
      case TYO: count_tyo++; break;
      case PAA: count_paa++; break;
    }
  }
}


int main() {
  while (true) {
    cin >> c[0];
    if (c[0] == 0) break;
    cin >> c[1] >> c[2] >> c[3] >> c[4];
    int a[5]; // answer
    count();
    // kati/make
    if (!((count_gu == 5 || count_paa == 5 || count_tyo == 5) ||
        (count_gu != 0 && count_tyo != 0 && count_paa == 0))) {
      // tyo -> win / paa -> lose
      if (count_gu == 0) {
        rep(i, 5) {
          if (c[i] == TYO) a[i] = WIN;
          else             a[i] = LOSE;
        }
      }
      // tyo -> lose / gu -> win
      if (count_paa == 0) {
        rep(i, 5) {
          if (c[i] == GU) a[i] = WIN;
          else            a[i] = LOSE;
        }
      }
      // paa -> win / gu -> lose
      if (count_tyo == 0) {
        rep(i, 5) {
          if (c[i] == PAA) a[i] = WIN;
          else             a[i] = LOSE;
        }
      }
    }
    // aiko
    else rep(i, 5) a[i] = AIKO;

    rep(i, 5) cout << a[i] << endl;
  }
  return 0;
}

C++: # define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <complex>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) begin(x),end(x)
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl;
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

int main()
{
	int a[5];
	while (true)
	{
		cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
		if (!a[0])break;
		int x[4] = {};
		FOR(i, 5)
			x[a[i]]++;
		int g, c, p;
		g = x[1]; c = x[2]; p = x[3];
		if ((g&&c&&p) || (g&&!c&&!p) || (!g&&c&&!p) || (!g&&!c&&p))
		{
			FOR(i, 5)x[i] = 3;
		}
		else
		{
			if (g&&p)
			{
				x[1] = 2; x[3] = 1;
			}
			if (c&&g)
			{
				x[2] = 2; x[1] = 1;
			}
			if (p&&c)
			{
				x[3] = 2; x[2] = 1;
			}
		}
		FOR(i, 5)cout << x[a[i]] << endl;
	}
	return 0;
}

C++: # include <iostream>

int a[5];
bool f[3];
int res[5];

int main() {
	while (1) {
		std::cin >> a[0];
		if (!a[0])
			break;
		std::fill(f, f + 3, false);

		for (int i = 1; i < 5; ++i) {
			std::cin >> a[i];
			if (!f[a[i] - 1]) {
				switch (a[i]) {
				case 1:
					f[0] = true; break;
				case 2:
					f[1] = true; break;
				case 3:
					f[2] = true; break;
				}
			}
		}
		if (f[0] && f[1] && f[2])
			std::fill(res, res + 5, 3);

		else if ((f[0] && !f[1] && !f[2]) ||
			(f[1] && !f[0] && !f[2]) ||
			(f[2] && !f[0] && !f[1]))
			std::fill(res, res + 5, 3);

		else {
			for (int i = 0; i < 5; ++i) {
				if (f[0] && f[1])
					res[i] = (a[i] == 1) ? 1 : 2;
				else if (f[1] && f[2])
					res[i] = (a[i] == 2) ? 1 : 2;
				else if (f[0] && f[2])
					res[i] = (a[i] == 3) ? 1 : 2;
			}
		}
		for (int i = 0; i < 5; ++i)
			std::cout << res[i] << std::endl;
	}
	return 0;
}

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

bool is_draw(int* first, int* last) {
    bool used[3] = {false, false, false};
    for (int* p = first; p != last; p++) {
        used[*p - 1] = true;
    }
    return all_of(used, used + 3, [used](bool x) {return x;});
}

int get_win(int* first, int* last) {
    int mi = 5, ma = 0;
    for (int*p = first; p != last; p++) {
        mi = min(mi, *p);
        ma = max(ma, *p);
    }
    if (ma - mi == 1) return mi;
    return ma;
}

int main() {
    int hands[5];
    while (cin >> hands[0], hands[0]) {
        for (int i = 1; i < 5; i++) {
            cin >> hands[i];
        }
        if (is_draw(hands, hands + 5)) {
            for (int i = 0; i < 5; i++) {
                cout << 3 << endl;
            }
        }
        else {
            int win = get_win(hands, hands + 5);
            for (int i = 0; i < 5; i++) {
                if (hands[i] == win) {
                    cout << 1 << endl;
                }
                else {
                    cout << 2 << endl;
                }
            }
        }
    }
    return 0;
}

C++: // AOJ 0205
#include<iostream>
#include<set>

int main()
{
	int a[5];
	while( std::cin >> *a, *a )
	{
		std::set<int> s;
		s.insert( *a );
		for( int i = 1; i != 5; ++i )
		{
			std::cin >> a[i];
			s.insert( a[i] );
		}

		if( s.size() == 1 || s.size() == 3 )
			for( int i = 0; i != 5; ++i )
				std::cout << 3 << std::endl;
		else
		{
			int win = *s.begin() == 1 ? *( ++s.begin() ) == 2 ? 1 : 3 : 2;
			for( int i = 0; i != 5; ++i )
				std::cout << ( a[i] == win ? 1 : 2 ) << std::endl;
		}
	}

	return 0;
}

C++: #include<iostream>

using namespace std;

void Aiko ( void ) ;
void Shori ( int ) ;

int jan[4] = {0};
int mem[5];

int main () {
	
	while (cin >> mem[0],mem[0]){
		int hoge = 0;
		for ( int i = 0; i < 4; i++ ) {
			jan[i] = 0;
		}
		
		jan[mem[0]]++;
		for ( int i = 1; i < 5; i++ ) {
			cin >> mem[i];
			jan[mem[i]]++;
		}
		for ( int i = 1; i < 4; i++ ) {
			if ( jan[i] )	{
				hoge++;
			}
		}
		if ( hoge != 2 ){
			Aiko ();
		} else {
			for ( int i = 1; i < 4; i++ ) {
				if ( !jan[i] ) {
					if ( i == 1 ) {
						Shori (2);
					} else if ( i == 2 ) {
						Shori (3);
					} else {
						Shori (1);
					}
					break;
				}
			}
		}
	}
	return 0;
}

void Aiko () {
	for ( int i = 0; i < 5; i++ ) {
		cout << "3" << endl;
	}
}

void Shori (int Win) {
	for ( int i = 0; i < 5; i++ ) {
		if ( mem[i] == Win ) {
			cout << "1" << endl;
		} else {
			cout << "2" << endl;
		}
	}
}