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

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

using namespace std;

int main() {
    vector<int> hand(5);
    while(1) {
        cin >> hand[0];
        if (hand[0] == 0)break;
        for (int i = 1; i < 5; i++) {
            cin >> hand[i];
        }
        bool used[3] = {false};
        rep(i,5) {
            used[hand[i]-1] = true;
        }
        int count = 0;
        rep(i,3) {
            if (used[i])count++;
        }
        if (count == 1 || count == 3) {
            rep(i,5) {
                cout << 3 << endl;
            }
        } else {
            int win, lose;
            if (used[0] && used[1]) {
                win = 1;
            } else if (used[1] && used[2]) {
                win = 2;
            } else {
                win = 3;
            }
            rep(i,5) {
                if (hand[i] == win) {
                    cout << 1 << endl;
                } else {
                    cout << 2 << endl;
                }
            }
        }
    }
}

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

using namespace std;

int main() {
  for (;;) {
    int a[5], c[4];
    cin >> a[0];
    if (!a[0]) return 0;
    fill(c+1, c+4, 0);
    for (int i = 1; i < 5; i++)
      cin >> a[i];
    for (int i = 0; i < 5; i++)
      c[a[i]]++;
    int w = 0;
    if (!c[1] && c[2] && c[3])
      w = 2;
    else if (c[1] && !c[2] && c[3])
      w = 3;
    else if (c[1] && c[2] && !c[3])
      w = 1;
    if (w)
      for (int i = 0; i < 5; i++)
        cout << (a[i] == w ? 1 : 2) << endl;
    else
      for (int i = 0; i < 5; i++)
        cout << 3 << endl;
  }
}

C++: #include<iostream>

const int N = 5;

void solve(int *a){
	int r=0,s=0,p=0;
	for(int i=0; i<N; i++){
		switch(a[i]){
		case 1:
			r++;
			break;
		case 2:
			s++;
			break;
		case 3:
			p++;
			break;
		}
	}
	if((r && s && p) || r==5 || p==5 || s==5)
		for(int i=0; i<N; i++)
			std::cout << 3 << std::endl;
	else{
		int x = 0, y = 3;
		if(r == 0)
			y = 2;
		else if(p == 0)
			y = 1;
		for(int i=0; i<N; i++){
			if(a[i] == y)
				x = 1;
			else
				x = 2;
			std::cout << x << std::endl;
		}
	}
}

int main(){
	int n[N];
	while(true){
		for(int i=0; i<N; i++){
			std::cin >> n[i];
			if(!n[i])
				return 0;
		}
		solve(n);
	}

	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;
		}
		
		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;
		}
	}
}

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 <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 <unordered_set>
//#include <unordered_map>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


namespace{
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;
}


#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 MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int t;
	vint v(5);
	while(cin>>v[0],v[0]){
		vint a(4,0);
		a[v[0]]++;
		rep(i,4){
			cin>>v[i+1];
			a[v[i+1]]++;
		}
		if(a[1]&&a[2]&&a[3]){
			rep(i,5){
				cout<<3<<endl;
			}
		}
		else if(a[1]==5||a[2]==5||a[3]==5){
			rep(i,5){
				cout<<3<<endl;
			}
		}
		else{
			int win;
			if(a[1]==0){
				win=2;
			}
			else if(a[2]==0){
				win=3;
			}
			else{
				win=1;
			}
			rep(i,5){
				if(v[i]==win){
					cout<<1<<endl;
				}
				else{
					cout<<2<<endl;
				}
			}
		}
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

C++: #include<iostream>
#define G 1
#define C 2
#define P 3
#define N 5
using namespace std;

int a[N];

void calc() {

  int g,c,p;

  g=0;
  c=0;
  p=0;

  for ( int i=0; i<N; i++ ) {
    if ( a[i] == G )
      g = 1;
    if ( a[i] == C )
      c = 1;
    if ( a[i] == P )
      p = 1;
  }

  for ( int i=0; i<N; i++ ) {
    if ( ((g == c) && (c == p)) || (g && c && p) ) {
      cout << 3 << endl;
    } else {
      if ( g == 1 ) {
	if ( a[i] == G ) {
	  if ( c == 1 )
	    cout << 1 << endl;
	  else if ( p == 1 ) 
	    cout << 2 << endl;
	  else
	    cout << 3 << endl;
	}
	if ( a[i] == C ) {
	  cout << 2 << endl;
	}
	if ( a[i] == P ) {
	  cout << 1 << endl;
	}
      } else if ( c == 1 ) {
	if ( a[i] == G ) {
	  cout << 1 << endl;
	}
	if ( a[i] == C ) {
	  if ( g == 1 )
	    cout << 2 << endl;
	  else if ( p == 1 ) 
	    cout << 1 << endl;
	  else
	    cout << 3 << endl;
	}
	if ( a[i] == P ) {
	  cout << 2 << endl;
	}

      } else if ( p == 1 ) {
	if ( a[i] == G ) {
	  cout << 1 << endl;
	}
	if ( a[i] == C ) {
	  cout << 2 << endl;
	}
	if ( a[i] == P ) {
	  if ( g == 1 ) 
	    cout << 1 << endl;
	  else if ( c == 1 )
	    cout << 2 << endl;
	  else
	    cout << 3 << endl;
	}
      }
    }
  }
}

int main () {
  
  while ( true ) {
    bool skip = false;
    for ( int i=0; i<N; i++ ) {
      cin >> a[i];
      if ( a[i] == 0 ) {
	return 0;

      }

    }

    if ( a == 0 )
      break;

    calc();
  }
}