#include <cstdio>
#include <map>
using namespace std;
int w;

map<int, int> create_map() {
    map<int, int> m;
    m.insert({1, 0});
    m.insert({2, 0});
    m.insert({3, 0});
    return m;
}
map<int, int> m = create_map();
bool isEqual() {
    int idx = 0;
    for (int i = 1; i <= 3; i++) {
        if (m[i] == 5) { return true; }
        if (m[i] > 0) idx++;
    }
    return (idx == 3);
}

void setWinner() {
    if (m[3] == 0) w=1;
    else if (m[2] == 0) w=3;
    else if (m[1] == 0) w=2;
}

int main() {

    int p[5];
    for (; ;) {
        scanf("%d", &p[0]);
        if (p[0] == 0) break;
        m[1] = m[2] = m[3] = 0;
        m[p[0]]++;
        for (int i = 1; i < 5; i++) {
            scanf("%d", &p[i]);
            m[p[i]]++;
        }
        if (isEqual()) {
            for (int i = 0; i < 5; i++) printf("%d\n", 3);
        }
        else {
            setWinner();
            for (int i = 0; i < 5; i++) {
                (p[i] == w) ? printf("%d\n", 1) : printf("%d\n", 2);
            }
        }
    }

    return 0;
}

