#include<iostream>
using namespace std;

int main()
{
    int a[5], b[4];

    while( cin >> a[0] )
    {
        if( a[0] == 0 )
            break;
        for( int i = 0; i < 4; i++ )
            b[i] = 0;
        b[a[0]]++;
        for( int i = 1; i < 5; i++ )
        {
            cin >> a[i];
            b[a[i]]++;
        }

        if( b[1] != 0 && b[2] != 0 && b[3] != 0 || b[1] == 5 || b[2] == 5 || b[3] == 5 )
            for( int i = 0; i < 5; i++ )
                cout << 3 << endl;
        else
        {
            if( b[1] == 0 )
            {
                for( int i = 0; i < 5; i++ )
                    if( a[i] == 2 )
                        cout << 1 << endl;
                    else
                        cout << 2 << endl;
            }
            else if( b[2] == 0 )
            {
                for( int i = 0; i < 5; i++ )
                    if( a[i] == 3 )
                        cout << 1 << endl;
                    else
                        cout << 2 << endl;
            }
            else
            {
                for( int i = 0; i < 5; i++ )
                    if( a[i] == 1 )
                        cout << 1 << endl;
                    else
                        cout << 2 << endl;
            }
        }
    }
    return 0;
}
