#include <iostream>
#include <vector>
using namespace std;
int main()
{
  for(;;){
    vector<int> v(5);
    cin >> v[0];
    if(v[0] == 0) break;
    bool b1,b2,b3;
    b1 = b2 = b3 = false;
    switch(v[0]){
    case 1: b1 = true; break;
    case 2: b2 = true; break;
    case 3: b3 = true; break;
    }
    for(int i=1; i<5; i++){
      cin >> v[i];
      switch(v[i]){
      case 1: b1 = true; break;
      case 2: b2 = true; break;
      case 3: b3 = true; break;
      }
    }
    if(b1 && b2 && b3 || !b1 && !b2 || !b1 && !b3 || !b2 && !b3){
      for(int i=0; i<5; i++) cout << 3 << endl;
      continue;
    }
    if(b1 && b2){
      for(int i=0; i<5; i++){
        if(v[i] == 1) cout << 1 << endl;
        else cout << 2 << endl;
      }
      continue;
    }
    if(b1 && b3){
      for(int i=0; i<5; i++){
        if(v[i] == 3) cout << 1 << endl;
        else cout << 2 << endl;
      }
      continue;
    }
    if(b2 && b3){
      for(int i=0; i<5; i++){
        if(v[i] == 2) cout << 1 << endl;
        else cout << 2 << endl;
      }
      continue;
    }
  }
  return 0;
}