#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

void solve(){
}

int main(){
  while(1){
    int x[5];
    int cnt[] = {0,0,0};
    rep(i,5){
      if(cin>>x[i] && !x[i]) return 0;
      x[i]--;
      cnt[x[i]]++;
    }

    rep(i,5){
      if(cnt[0] && cnt[1] && cnt[2] || cnt[0] == 5 || cnt[1] == 5 || cnt[2] == 5){
        cout<<"3\n";
      }
      else if(cnt[(x[i] + 2) % 3]){
        cout<<"2\n";
      }
      else{
        cout<<"1\n";
      }
    }
  }
}