#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#include<bitset>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main(){
    vi v(5,0);
    vb flag(4,true);
    vvi u(4,vi(4,0));
    u[1][2]=1;u[2][3]=1;u[3][1]=1;
    while(cin>>v[0],v[0]){
        rep(i,4)flag[i]=true;
        rep(i,4)cin>>v[i+1];
        int cnt=0;
        rep(i,5)if(flag[v[i]]){flag[v[i]]=false; cnt++;}
        if(cnt==1||cnt==3){rep(i,5)cout<<3<<endl;goto L;}
        rep(i,5){
            rep(j,5){
                if(i==j||v[i]==v[j])continue;
                if(u[v[i]][v[j]]){cout<<"1"<<endl; break;}
                else {cout<<"2"<<endl;break;}
            }
        }
    L:;
    }
}