#include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
#define print(Target) cout << Target << '\n'
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;

bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

int winner(int a, int b)
{
  if (a == 1 && b == 2) return (1);
  if (a == 2 && b == 3) return (2);
  if (a == 1 && b == 3) return (3);
}

signed main()
{
  ios::sync_with_stdio(false);
  int input[5];
  
  while (cin >> input[0], input[0]){
    bool check[4] = {false};
    check[input[0]] = true;
    REPS(i, 1, 5){
      cin >> input[i];
      check[input[i]] = true;
    }

    int out[2], j = 0;
    int only = 0;
    REPS(i, 1, 4){
      if (!check[i]){
        only++;
      }
      else {
        out[j++] = i;
      }
    }

    if ((check[1] && check[2] && check[3]) || only == 2){
      REP(i, 5){
        print("3");
      }
    }
    else {
      int win = winner(out[0], out[1]);
      REP(i, 5){
        if (input[i] == win){
          print("1");
        }
        else {
          print("2");
        }
      }
    }
  }

  return (0);
}