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