#include <iostream>

using namespace std;

const int N=5;

int main(void){
  int cnt[3];
  int h[N];
  
  while (cin >> h[0], h[0]){
    for (int i=1; i<N; i++) cin >> h[i];
    for (int i=0; i<3; i++) cnt[i]=0;
    for (int i=0; i<N; i++) cnt[h[i]-1]++;
    //cout << cnt[0] << " " << cnt[1] << " " << cnt[2] << endl;
    if (cnt[0]+cnt[1]==0 ||
      cnt[1]+cnt[2]==0 ||
      cnt[2]+cnt[0]==0 ||
      cnt[0]*cnt[1]*cnt[2]){
      for (int i=0; i<N; i++){
        cout << 3 << endl;
      }
    } else {
      for (int i=0; i<N; i++){
        cout << (cnt[(h[i]+1)%3]?2:1) << endl;
      }
    }
  }
  return 0;
}

