#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int h[5];
  while (cin >> h[0], h[0]) {
    for (int i = 1; i < 5; i++) {
      cin >> h[i];
    }
    map<int, int> mp;
    for (int i = 0; i < 5; i++) {
      mp[h[i]]++;
    }
    if (mp.size() == 1 || mp.size() == 3) {
      for (int i = 0; i < 5; i++) {
        cout << 3 << endl;
      }
    } else {
      auto it = mp.begin();
      int a = it->first, b = (++it)->first;
      if (a > b) swap(a, b);
      if (a == 1 && b == 3) swap(a, b);
      for (int i = 0; i < 5; i++) {
        cout << (h[i] == a ? 1 : 2) << endl;
      }
    }
  }

  return 0;
}
