#include <iostream>

using namespace std;

int main()
{
    while(1)
    {
        int a[5],b=0;
        bool use[3]={0};
        for(int i=0;i<5;++i){
            cin>>a[i];if(!a[i])return 0;
            switch(a[i]){
                case 1:use[0]=1;break;
                case 2:use[1]=1;break;
                case 3:use[2]=1;break;
            }
        }
        for(int i=0;i<3;++i){
            b+=use[i];
        }
        if(b!=2){
            for(int i=0;i<5;++i){
                cout<<3<<endl;
            }
        }else{
            for(int i=0;i<5;++i){
                if(use[0]&use[1]){
                    if(a[i]!=2)cout<<1<<endl;
                    else cout<<2<<endl;
                }
                if(use[1]&use[2]){
                    if(a[i]!=3)cout<<1<<endl;
                    else cout<<2<<endl;
                }
                if(use[0]&use[2]){
                    if(a[i]!=1)cout<<1<<endl;
                    else cout<<2<<endl;
                }
            }
        }
    }
}