#include<iostream>
using namespace std;
#define GOO 1
#define CHO 2
#define PA 3
#define WIN 1
#define LOSE 2
#define EVEN 3
int main()
{
    while(true)
    {
        int field[5] ={};
        int te[5] = {};
        bool fin= false;
        cin >> te[0];
        if(te[0] == 0)break;
        field[te[0] ] = 1;
        for(int i=1;i<5;i++)
        {
            cin >> te[i];
            field[te[i]] = 1;
            //if(cin.eof()){fin = true; break;}
        }
        if(fin)break;


        //  aiko
        int tekazu = 0;
        for(int i=1;i<=3;i++)
        {
            tekazu += field[i];
        }
        //cout << tekazu << endl;
        if((tekazu == 3) || (tekazu == 1) )
        {
            for(int i=0;i<5;i++){ cout << EVEN << endl;}
            continue;
        }
        if(field[GOO] == 0)
        {
            for(int i=0;i<5;i++)
            {
                if(te[i] == CHO) cout << WIN<<endl;
                else cout << LOSE << endl;
            }
        }
        if(field[CHO] == 0)
        {
            for(int i=0;i<5;i++)
            {
                if(te[i] == PA) cout << WIN<<endl;
                else cout << LOSE << endl;
            }
        }
        if(field[PA] == 0)
        {
            for(int i=0;i<5;i++)
            {
                if(te[i] == GOO) cout << WIN<<endl;
                else cout << LOSE << endl;
            }
        }
    }
    return 0;
}