#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    int a[5];
    while (cin >> a[0], a[0]) {
        for (int i=1; i<5; ++i) {
            cin >> a[i];
        }
        int r = 0, p = 0, s = 0;
        for (int i=0; i<5; ++i) {
            if (a[i] == 1) r ++;
            else if (a[i] == 2) p ++;
            else s ++;
        }
        int res[4];
        if ((0 < r && 0 < p && 0 < s) || r == 5 || p == 5 || s == 5) {
            cout << "3\n3\n3\n3\n3\n";
        } else {
            if (r == 0) {
                res[2] = 1;
                res[3] = 2;
            } else if (p == 0) {
                res[1] = 2;
                res[3] = 1;
            } else if (s == 0) {
                res[1] = 1;
                res[2] = 2;
            }
            for (int i=0; i<5; ++i) {
                cout << res[a[i]] << endl;
            }
        }
    }
    return 0;
}