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