#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define rep(i,n) for(int i=0; i<(n); i++)

using namespace std;

int main() {
    vector<int> hand(5);
    while(1) {
        cin >> hand[0];
        if (hand[0] == 0)break;
        for (int i = 1; i < 5; i++) {
            cin >> hand[i];
        }
        bool used[3] = {false};
        rep(i,5) {
            used[hand[i]-1] = true;
        }
        int count = 0;
        rep(i,3) {
            if (used[i])count++;
        }
        if (count == 1 || count == 3) {
            rep(i,5) {
                cout << 3 << endl;
            }
        } else {
            int win, lose;
            if (used[0] && used[1]) {
                win = 1;
            } else if (used[1] && used[2]) {
                win = 2;
            } else {
                win = 3;
            }
            rep(i,5) {
                if (hand[i] == win) {
                    cout << 1 << endl;
                } else {
                    cout << 2 << endl;
                }
            }
        }
    }
}