#include<bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]){
  int n[5];
  while(std::cin >> n[0], n[0]){
    n[0]--;
    for (int i = 0; i < 4; i++) {
      std::cin >> n[i + 1];
      n[i + 1]--;
    }
    bool used[3] = {}, draw = false;
    for (int i = 0; i < 5; i++) {
      used[n[i]] = true;
    }
    int win = -1;
    set<int> a;
    vector<int> ans;
    for (int i = 0; i < 5; i++) {
      a.insert(n[i]);
    }
    for (int i: a){
      ans.push_back(i);
    }
    if(ans.size() == 1 || ans.size() == 3){
      draw = true;
    }else if(ans[0] == 0 && ans[1] == 1){
      win = 0;
    }else if(ans[0] == 1 && ans[1] == 2){
      win = 1;
    }else if(ans[0] == 0 && ans[1] == 2){
      win = 2;
    }
    if(draw){
      for (int i = 0; i < 5; i++) {
        std::cout << 3 << std::endl;
      }
    }else{
      for (int i = 0; i < 5; i++) {
        if(win == n[i])std::cout << 1 << std::endl;
        else std::cout << 2 << std::endl;
      }
    }
  }
  return 0;
}