#include<iostream>
#include<vector>
#include<algorithm>
#define N 5

using namespace std;

void RockWin(vector<int>&);
void ScissorsWin(vector<int>&);
void PaperWin(vector<int>&);
void Draw(vector<int>&);

int main(){
  int i, x;
  vector<int> data;
  vector<int>::iterator rock, scissors, paper;

  while(1){
    cin >> x;
    if(x == 0) break;
    data.push_back(x);
    for(i=1; i<N; ++i){
      cin >> x;
      data.push_back(x);
    }

    rock = find(data.begin(), data.end(), 1);
    scissors = find(data.begin(), data.end(), 2);
    paper = find(data.begin(), data.end(), 3);

    if(rock != data.end() && scissors != data.end() && paper == data.end())
      RockWin(data);
    else if(rock == data.end() && scissors != data.end() && paper != data.end())
      ScissorsWin(data);
    else if(rock != data.end() && scissors == data.end() && paper != data.end())
      PaperWin(data);
    else
      Draw(data);

    for(i=0; i<data.size(); ++i)
      cout << data[i] << endl;

    data.clear();
  }

  return 0;
}

void RockWin(vector<int>& data){
  int i;
  for(i=0; i<data.size(); ++i){
    if(data[i] == 1) data[i] = 1;
    else data[i] = 2;
  }
}

void ScissorsWin(vector<int>& data){
  int i;
  for(i=0; i<data.size(); ++i){
    if(data[i] == 2) data[i] = 1;
    else data[i] = 2;
  }
}

void PaperWin(vector<int>& data){
  int i;
  for(i=0; i<data.size(); ++i){
    if(data[i] == 3) data[i] = 1;
    else data[i] = 2;
  }
}

void Draw(vector<int>& data){
  int i;
  for(i=0; i<data.size(); ++i)
    data[i] = 3;
}