#include <iostream>
using namespace std;

void printResult(int win, int* array) {
    for (int i = 0; i < 5; i++) {
        if (array[i] == win) {
            cout << 1 << endl;
        } else {
            cout << 2 << endl;
        }
    }
}

int main() {
    while (true) {
        int hands[5];
        for (int i = 0; i < 5; i++) {
            cin >> hands[i];
            if (hands[i] == 3) {
                hands[i] = 4;
            }
        }
        if (hands[0] == 0) {
            break;
        }
        int result = hands[0] | hands[1] | hands[2] | hands[3] | hands[4];
        switch (result) {
        case 1: case 2: case 4: case 7:
            for (int i = 0; i < 5; i++) {
                cout << 3 << endl;
            }
            break;
        case 3:
            printResult(1, hands);
            break;
        case 6:
            printResult(2, hands);
            break;
        case 5:
            printResult(4, hands);
            break;
        }
    }
}