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>
using namespace std;
int main(void){
  int RPS[5],R,P,S;
  while(1){
    R = P = S = 0;
    for(int i=0;i<5;i++){cin>>RPS[i];if(RPS[0]==0)break;if(RPS[i]==1)R++;else if(RPS[i]==2)S++;else P++;}
    if(RPS[0]==0)break;
    if(R>0&&S>0&&P>0||R==5||S==5||P==5){for(int i=0;i<5;i++)cout<<"3"<<endl;}
    else if(R==0){for(int i=0;i<5;i++){if(RPS[i]==2)cout<<"1"<<endl;else cout<<"2"<<endl;}}
    else if(S==0){for(int i=0;i<5;i++){if(RPS[i]==3)cout<<"1"<<endl;else cout<<"2"<<endl;}}
    else if(P==0){for(int i=0;i<5;i++){if(RPS[i]==1)cout<<"1"<<endl;else cout<<"2"<<endl;}}
  }
  return 0;
}

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

using namespace std;

void solve()
{
	int a[5];
	while(cin >> a[0], a[0])
	{
		for(int i = 1; i < 5; ++i)
		{
			cin >> a[i];
		}
		map<int, int> Map;
		for(int i = 0; i < 5; ++i)
		{
			Map[a[i]]++;
		}
		if(Map.size() == 1 || Map.size() == 3)
		{
			for(int i = 0; i < 5; ++i)
			{
				cout << 3 << endl;
			}
		}
		else
		{
			if(Map.find(1) != Map.end() && Map.find(2) != Map.end())
			{
				for(int i = 0; i < 5; ++i)
				{
					if(a[i] == 1)
					{
						cout << 1 << endl;
					}
					else
					{
						cout << 2 << endl;
					}
				}
			}
			else if(Map.find(1) != Map.end() && Map.find(3)!= Map.end() )
			{
				for(int i = 0; i < 5; ++i)
				{
					if(a[i] == 1)
					{
						cout << 2 << endl;
					}
					else
					{
						cout << 1 << endl;
					}
				}
			}
			else if(Map.find(2) != Map.end() && Map.find(3)!= Map.end() )
			{
				for(int i = 0; i < 5; ++i)
				{
					if(a[i] == 2)
					{
						cout << 1 << endl;
					}
					else
					{
						cout << 2 << endl;
					}
				}
			}
		}
	}
}

int main()
{
	solve();
	return(0);
}

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++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	vector<int>h(5);
	while (cin >> h[0], h[0]) {
		vector<int>aiko(4, 0);
		aiko[h[0]]++;
		rep(i, 1, 5) {
			cin >> h[i]; aiko[h[i]]++;
		}
		if (aiko[1] && aiko[2] && aiko[3])rep(i,0,5)cout << 3 << endl;
		else {
			int win, lose;
			if (aiko[1] == 0) { win = 2; lose = 3; }
			else if (aiko[2] == 0) { win = 3; lose = 1; }
			else win = 1; lose = 2;
			rep(i, 0, 5) {
				if (h[i] == win)cout << 1 << endl;
				else cout << 2 << endl;
			}


		}

	}
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);++i)

int main() {
  for (;;) {
      cin >> ws;
      if (cin.eof())break;
      int hand[5];
      REP(i, 5) cin >> hand[i];
      if(hand[0] == 0) break;
      REP(i, 5) hand[i]--;

      int exist = 0;
      REP(i, 5) exist |= 1 << hand[i];

      REP(i, 5) {
          if (exist == 7) cout << 3 << endl;
          else if (exist == 1 || exist == 2 || exist == 4) cout << 3 << endl;
          else {
              int win = 0;
              REP(j, 5) if (hand[i] != hand[j]) {
                  if ((hand[j] - hand[i] + 3) % 3 == 1) win = 1;
              }
              if (win) cout << 1 << endl;
              else 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};
    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;
  }
}