#include <iostream>
using namespace std;

int a[5];

bool input() {
  cin >> a[0];
  if (!a[0]) {
    return false;
  }
  for (int i = 1; i < 5; ++i) {
    cin >> a[i];
  }
  return true;
}

void print_aiko() {
  for (int i = 0; i < 5; ++i) {
    cout << 3 << endl;
  }
}

void print_win_lose(int d) {
  for (int i = 0; i < 5; ++i) {
    if (a[i] == (d + 1) % 3 + 1) {
      cout << 1 << endl;
    } else {
      cout << 2 << endl;
    }
  }
}

void solve() {
  int c[3] = {0};
  for (int i = 0; i < 5; ++i) {
    ++c[a[i] - 1];
  }
  int b = 0;
  for (int i = 0; i < 3; ++i) {
    if (c[i]) {
      ++b;
    }
  }
  if (b == 1 || b == 3) {
    print_aiko();
    return;
  }
  int d = -1;
  for (int i = 0; i < 3; ++i) {
    if (!c[i]) {
      d = i;
      break;
    }
  }
  print_win_lose(d);
}

int main() {
  while (input()) {
    solve();
  }
}