#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  for (;;) {
    int a[5], c[4];
    cin >> a[0];
    if (!a[0]) return 0;
    fill(c+1, c+4, 0);
    for (int i = 1; i < 5; i++) {
      cin >> a[i];
      c[a[i]]++;
    }
    int w = 0;
    if (!c[1] && c[2] && c[3])
      w = 2;
    else if (c[1] && !c[2] && c[3])
      w = 3;
    else if (c[1] && c[2] && !c[3])
      w = 1;
    if (w)
      for (int i = 0; i < 5; i++)
        cout << (a[i] == w ? 1 : 2) << endl;
    else
      for (int i = 0; i < 5; i++)
        cout << 3 << endl;
  }
}