#include <iostream>
#include <cstring>

using namespace std;

int judge(int a, int b) { // aがbにかつかどうか
//    cout << a << ' ' << b << endl;
    if (a == 1) {
        if (b == 1) return 3;
        if (b == 2) return 1;
        if (b == 3) return 2;
    } 
    if (a == 2) {
        if (b == 1) return 2;
        if (b == 2) return 3;
        if (b == 3) return 1;
    } 
    if (a == 3) {
        if (b == 1) return 1;
        if (b == 2) return 2;
        if (b == 3) return 3;
    }
}


void result(int *h) {
    // 3つ同じ手
    if (h[0] == h[1] && h[1] == h[2] && h[2] == h[3] && h[3] == h[4]) {
        for (int i = 0; i < 5; i++) h[i] = 3;
        return;
    }

    // 3つ違う手
    bool hand_used[3+1];
    memset(hand_used, 0, sizeof(hand_used));
    for (int i = 0; i < 5; i++) {
        hand_used[h[i]] = true;
    }
    if (hand_used[1] && hand_used[2] && hand_used[3]) {
        for (int i = 0; i < 5; i++) h[i] = 3;
        return;
    }

    if (hand_used[1] && hand_used[2]) {
        for (int i = 0; i < 5; i++) {
            if (h[i] == 1) h[i] = judge(1, 2);
            else           h[i] = judge(2, 1);
        }
        return;
    }
    if (hand_used[2] && hand_used[3]) {
        for (int i = 0; i < 5; i++) {
            if (h[i] == 2) h[i] = judge(2, 3);
            else           h[i] = judge(3, 2);
        }
        return;
    }
    if (hand_used[3] && hand_used[1]) {
        for (int i = 0; i < 5; i++) {
            if (h[i] == 3) h[i] = judge(3, 1);
            else           h[i] = judge(1, 3);
        }
        return;
    }
}



int main() {
    int h[5];
    while (cin >> h[0], h[0] != 0) {
        for (int i = 1; i < 5; i++) {
            cin >> h[i];
        }
        result(h);
        for (int i = 0; i < 5; i++) {
            cout << h[i] << endl;
        }
    }
    return 0;
}