#include<bits/stdc++.h>
using namespace std;
int main()
{
    int num[5];
    while(cin>>num[0],num[0]){
        vector<int> hand(5,0);
        hand[num[0]]=1;
        for(int i=1;i<5;i++){
            cin>>num[i];
            hand[num[i]]++;
        }
        if(hand[1]&&hand[2]&&hand[3]||hand[1]==5||hand[2]==5||hand[3]==5)
            for(int i=0;i<5;i++)cout<<"3\n";
        else {
            int win;
            if(!hand[3])win=1;
            else if(!hand[1])win=2;
            else win=3;
            for(int i=0;i<5;i++){
                if(win==num[i])cout<<"1\n";
                else cout<<"2\n";
            }
        }
    }
}