#include <iostream>
using namespace std;

void search(int a[], int c[]) {
  for (int i = 0; i < 5; i++) {
    if (a[i] == 1) {
      c[0]++;
    } else if (a[i] == 2) {
      c[1]++;
    } else {
      c[2]++;
    }
  }
}

int main() {
  int h[5];
  
  while (true) {
    cin >> h[0];
    if (h[0] == 0) break;
    for (int i = 1; i < 5; i++)
      cin >> h[i];

    int count[3] = {0};
    search(h, count);
    int count0 = 0;
    for (int i = 0; i < 3; i++)
      if (count[i] == 0) count0++;
    if (count0 != 1) {
      for (int i = 0; i < 5; i++)
	cout << 3 << endl;
    } else {
      for (int j = 0; j < 5; j++) {
	if (count[0] && count[1]) {
	  if (h[j] == 1) cout << 1 << endl;
	  else cout << 2 << endl;
	} else if (count[1] && count[2]) {
	  if (h[j] == 2) cout << 1 << endl;
	  else cout << 2 << endl;
	} else {
	  if (h[j] == 3) cout << 1 << endl;
	  else cout << 2 << endl;
	}
      }
    }
  }
  return 0;
}