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

int searchWin(int a, int b);

int main(){
    int a[5];
    while(cin >>a[0]){
        vector<int> vec(4, 0);
        if(a[0] == 0) break;
        vec[a[0]]++;
        bool aiko = false;
        for(int i = 1; i < 5; i++){
            cin >>a[i];
            vec[a[i]]++;
        }

        if(vec[1] != 0 && vec[2] != 0 && vec[3] != 0) aiko = true;
        if((vec[1] == 0 && vec[2] == 0) || (vec[2] == 0 && vec[3] == 0) || (vec[3] == 0 && vec[1] == 0)) aiko = true;

        if(aiko){
            for(int i = 0; i < 5; i++) cout <<3 <<endl;
        } else{
            vector<int> v;
            for(int i = 1; i <= 3; i++){
                if(vec[i] != 0) v.push_back(i);
            }
            int win = searchWin(v[0], v[1]);
            for(int i = 0; i < 5; i++){
                if(win == a[i]) cout <<1 <<endl;
                else cout <<2 <<endl;
            }
        }
    }
    return 0;
}

int searchWin(int a, int b){
    if(a == 1){
        if(b == 2) return a;
        else return b;
    } else if(a == 2){
        if(b == 1) return b;
        else return a;
    } else{
        if(b == 1) return a;
        else return b;
    }
}