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<stdio.h>
int main(void)
{
	int a[5]={0};
	int guu=0,tyoki=0,paa=0;
	int n=1;
	int i=0;
	while(n!=0)
	{
		for (i=0;i<5;i++)
		{
			scanf("%d",&a[i]);
			
			if (a[i]==0)
			{
				break;
			}
			else if (a[i]==1)
			{
				guu=1;
			}
			else if(a[i]==2)
			{
				tyoki=1;
			}
			else if (a[i]==3)
			{
				paa=1;
			}
		}
		if (a[i]==0)
		{
			break;
		}
		for (i=0;i<5;i++)
		{
			if (guu==1&&tyoki==1&&paa==1)
			{
				printf("3\n");
			}
			else if (guu==1&&tyoki==1&&paa==0)
			{
				if (a[i]==1)
				{
					printf("1\n");
				}
				else
				{
					printf("2\n");
				}
			}
			else if (guu==1&&tyoki==0&&paa==0)
			{
				printf("3\n");
			}
			else if (guu==1&&tyoki==0&&paa==1)
			{
				if (a[i]==1)
				{
					printf("2\n");
				}
				else
				{
					printf("1\n");
				}
			}
			else if (tyoki==1&&paa==1)
			{
				if (a[i]==2)
				{
					printf("1\n");
				}
				else
				{
					printf("2\n");
				}
			}
			else if (tyoki==1&&paa==0)
			{
				printf("3\n");
			}
			else if (paa==1)
			{
				printf("3\n");
			}
			a[i]=0;
		}
			guu=0,tyoki=0,paa=0;
	}
}

C++: 
#include <cstdio>

using namespace std;

int main( void )
{

	int hand_list[5];
	int hands;
	while( 1 )
	{
		hands = 0;

		for( int i = 0; i < 5; ++i )
		{
			scanf( "%d", &hand_list[i] );
			if( hand_list[0] == 0 )
				goto end_0205;
			hands |= 1 << (hand_list[i] - 1);
		}

		for( int i = 0; i < 5; ++i )
		{
			if( hands == 0x0001 || hands == 0x0002 || hands == 0x0004 || hands == 0x0007 )
			{
				puts( "3" );
			}
			else
			{
				if( hands == 0x0003 )
				{
					if( hand_list[i] == 2 ) puts( "2" );
					else puts( "1" );
				}
				else if( hands == 0x0006 )
				{
					if( hand_list[i] == 3 ) puts( "2" );
					else puts( "1" );
				}
				else if( hands == 0x0005 )
				{
					if( hand_list[i] == 1 ) puts( "2" );
					else puts( "1" );
				}
			}
		}
	}

end_0205:
	return 0;

}

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 << 2 << 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 << 1 << 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();
  }
}

C++: #include <cstdio>

#define CH_G(a, g) (a == 1) ? true : g
#define CH_C(a, c) (a == 2) ? true : c
#define CH_P(a, p) (a == 3) ? true : p


int main(void)
{
	int hand[5];
	int i;
	bool g, c, p;
	
	while (1){
		g = c = p = false;
		
		scanf("%d", &hand[0]);
		if (hand[0] == 0) break;
		
		for (i = 1; i < 5; i++){
			scanf("%d", &hand[i]);
			g = CH_G(hand[i], g);
			c = CH_C(hand[i], c);
			p = CH_P(hand[i], p);
		}
		
		if ((g && c && p) || (g && !c && !p) || (!g && c && !p) || (!g && !c && p)){
			for (i = 0; i < 5; i++) printf("3\n");
		}
		else if (g && c){
			for (i = 0; i < 5; i++){
				if (hand[i] == 1) printf("1\n");
				else printf("2\n");
			}
		}
		else if (g && p){
			for (i = 0; i < 5; i++){
				if (hand[i] == 3) printf("1\n");
				else printf("2\n");
			}
		}
		else if (c && p){
			for (i = 0; i < 5; i++){
				if (hand[i] == 2) printf("1\n");
				else printf("2\n");
			}
		}
	}
	
	return (0);
}

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

int main()
{
  int hand[5];

  for(;cin>>hand[0],hand[0];)
    {
      int ans[5]={3,3,3,3,3};
      bool check[4]={false,false,false,false};
        check[hand[0]]=true;
      for(int i=1;i<5;i++)
	{
	  cin>>hand[i];
	  check[hand[i]]=true;
	}
      //      for(int i=1;i<4;i++)
      //	cout<<check[i]<<endl;
      for(int i=0;i<5;i++)
	{
	  if(hand[i]==1)
	    {
	      if(check[2])
		ans[i]=1;
	      if(check[3])
		ans[i]=2;
	    }
	 else if(hand[i]==2)
	    {
	      if(check[3])
		ans[i]=1;
	      if(check[1])
		ans[i]=2;
	    }
	 else if(hand[i]==3)
	    {
	      if(check[1])
		ans[i]=1;
	      if(check[2])
		ans[i]=2;
	    }	  
	}

      for(int i=1;i<4;i++)
	{
	  if(!check[i])
	    {
	      for(int j=0;j<5;j++)
		cout<<ans[j]<<endl;
	      break;
	    }
	  if(i==3)
	    {
	      for(int j=0;j<5;j++)
		cout<<"3"<<endl;
	    }
	}
    }
}

C++: #include <cstdio>

using namespace std;

int main()
{
	while (1){
		int hand[5];
		int state = 0;
		
		for (int i = 0; i < 5; i++){
			scanf("%d",hand + i);
			if (hand[i] == 0) return (0);
			state |= (1 << (hand[i] - 1));
		}
		
		if (__builtin_popcount(state) != 2){
			printf("3\n3\n3\n3\n3\n");
		}
		else {
			if (state == 5){
				for (int i = 0; i < 5; i++) printf("%d\n", hand[i] == 1 ? 2 : 1);
			}
			if (state == 6){
				for (int i = 0; i < 5; i++) printf("%d\n", hand[i] == 3 ? 2 : 1);
			}
			if (state == 3){
				for (int i = 0; i < 5; i++) printf("%d\n", hand[i] == 2 ? 2 : 1);
			}
		}
	}
}

C++: #include<iostream>

using namespace std;

int main(){

  int data[5], d[3];

  while(1){

    cin >> data[0];
    if(data[0] == 0) break;

    for(int i = 0; i < 3; i++) d[i] = 0;


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

      if(data[i] == 1) d[0]++;
      else if(data[i] == 2) d[1]++;
      else d[2]++;
    }

      if(d[0] > 0 && d[1] > 0 && d[2] > 0 || d[0] == 5 || d[1] == 5 || d[2] == 5){
	for(int j = 0; j < 5; j++) cout << "3" << endl;
      }else if(d[0] == 0){
	for(int j = 0; j < 5; j++){
	  if(data[j] == 2) cout << "1" << endl;
	  else cout << "2" << endl;
	}
      }else if(d[1] == 0){
	for(int j = 0; j < 5; j++){
	  if(data[j] == 3) cout << "1" << endl;
	  else cout << "2" << endl;
	}
      }else{
	for(int j = 0; j < 5; j++){
	  if(data[j] == 1) cout << "1" << endl;
	  else cout << "2" << endl;
	}
      }
  }

  return 0;
}