#include <bits/stdc++.h>

using namespace std;

#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, int> P;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int h[5];
  while(cin >> h[0], h[0]) {    
    int rps[3] = {0};
    rps[--h[0]]++;
    reps(i, 1, 5) cin >> h[i], rps[--h[i]]++;
    int win = 3;
    if(rps[0] && rps[1] && rps[2]) win = 3;
    else if(rps[0] && rps[1]) win = 0;
    else if(rps[1] && rps[2]) win = 1;
    else if(rps[2] && rps[0]) win = 2;
    rep(i, 5) {
      if(win == 3) cout << 3 << endl;
      else if(h[i] == win) cout << 1 << endl;
      else cout << 2 << endl;
    }
  }  
  return 0;
}