#include <iostream>
using namespace std;

int main() {


  while(1) {
    int a[5];
    int tu[3]={};
    for(int i=0;i<5;i++) {
      cin >> a[i];
      if(a[0] == 0) break;
      tu[a[i]-1]++;
    }

    if(a[0] == 0) break;

    int count = 0;
    int win = a[0];
    for(int i=1;i<5;i++) {
      if(a[0] == 1 && a[i] == 3) win = 3;
      else if(a[0] == 2 && a[i] ==1) win =1;
      else if(a[0] == 3 && a[i] == 2)win = 2;
    }
    for(int i=0;i<3;i++)
      if(tu[i] > 0) count++;
    
    if(count == 3 || count == 1){
      for(int i=0;i<5;i++) cout << 3 << endl;
      continue;
    }

    for(int i=0;i<5;i++) {
      if(a[i] == win) cout << 1 << endl;
      else cout << 2 << endl;
    }

    
  
  }
  
  return 0;
  
}
  