#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int te[5];
int main() {
  while (true) {
    vector<int> cnt(3, 0);
    REP(i, 5) {
      int v;
      if (scanf("%d", &v), v == 0) { return 0; }
      v--;
      te[i] = v;
      cnt[v]++;
    }
    REP(i, 5) {
      int win = 2;
      if (cnt[te[i]] == 5 || (cnt[0] > 0 && cnt[1] > 0 && cnt[2] > 0)) {
        win = 3;
      } else if (cnt[(te[i] + 2) % 3] == 0) {
        win = 1;
      }
      printf("%d\n", win);
    }
  }
}