#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int h[5];
    while(true) {
        cin >> h[0];
        if(h[0] == 0) break;
        
        cin >> h[1] >> h[2] >> h[3] >> h[4];
        
        int table[3];
        for(int i = 0; i < 3; i++) {
            table[i] = 0;
        }
        for(int i = 0; i < 5; i++) {
            table[h[i]-1] = 1;
        } 

        int s = table[0] + table[1] + table[2];
        int win, lose;
        if(s != 2) {
            for(int i = 0; i < 5; i++) {
                cout << 3 << endl;
            }
        } else {
            if(table[0] == 0) {
                win = 2;
                lose = 3;
            } else if(table[1] == 0) {
                win = 3;
                lose = 1;
            } else if(table[2] == 0) {
                win = 1;
                lose = 2;
            }
            for(int i = 0; i < 5; i++) {
                if(h[i] == win) {
                    cout << 1 << endl;
                } else {
                    cout << 2 << endl;
                }
            }
        }
    }
}

