#include <iostream>
#include <map>
using namespace std;

#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define mp make_pair

int hand[5];

// rock -> 1, scissor -> 2, paper -> 3

void solve() {
  REP(i,1,5) cin>>hand[i];
  
  map<int,int> var;
  rep(i,5) {
    if (!var.count(hand[i])) var.insert(mp(hand[i],0));
  }
  
  if (var.size() == 3 || var.size() == 1) {
    rep(i,5) cout<<3<<endl; return;
  }
  
  // rock vs scissor
  if (!var.count(3)) {
    rep(i,5)
    if (hand[i]==1) {
      cout<<1<<endl;
    } else {
      cout<<2<<endl;
    }
  }
  // rock vs paper
  else if (!var.count(2)) {
    rep(i,5)
    if (hand[i]==3) {
      cout<<1<<endl;
    } else {
      cout<<2<<endl;
    }
  }
  // scissor vs paper
  else if (!var.count(1)) {
    rep(i,5)
    if (hand[i]==2) {
      cout<<1<<endl;
    } else {
      cout<<2<<endl;
    }
  }
}

int main (int argc, char const* argv[]) {
  while (cin>>hand[0], hand[0]) {
    solve();
  }
  return 0;
}