#include <iostream>
using namespace std;

int main()
{
  int a[5];
  
  while (cin >> a[0] && a[0] != 0){
    cin >> a[1] >> a[2] >> a[3] >> a[4];
    int c[4] = {0};
    int cnt = 0;
    c[a[0]]++;
    for (int i = 1; i < 5; i++){
      c[a[i]]++;
      if (a[i] == a[i - 1]){
        cnt++;
      }
    }
    if (cnt == 4){
      for (int i = 0; i < 5; i++){
        cout << 3 << endl;
      }
      continue;
    }
    if (c[1] > 0 && c[2] > 0 && c[3] > 0){
      for (int i = 0; i < 5; i++){
        cout << 3 << endl;
      }
      continue;
    }
    for (int i = 1; i < 4; i++){
      if (c[i] == 0) cnt = i;
    }

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