#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;

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

        int cnt1, cnt2, cnt3;
        cnt1 = cnt2 = cnt3 = 0;
        rep(i, 5) {
            if (h[i] == 1) cnt1++;
            else if (h[i] == 2) cnt2++;
            else cnt3++;
        }
        
        if (cnt1 == 5 || cnt2 == 5 || cnt3 == 5 || cnt1*cnt2*cnt3 > 0) rep(i, 5) cout << 3 << endl;
        else {
            if (cnt1 == 0) rep(i, 5) {
                if (h[i] == 2) cout << 1 << endl;
                else cout << 2 << endl;
            } else if (cnt2 == 0) rep(i, 5) {
                if (h[i] == 3) cout << 1 << endl;
                else cout << 2 << endl;
            } else rep(i, 5) {
                if (h[i] == 1) cout << 1 << endl;
                else cout << 2 << endl;
            }
        }
    }

    return 0;
}
