#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;
int main(void) {
  int i,j;
  vi hand(5);
  while(1){
    vi n(3,0);
    cin>>hand[0];
    if(hand[0]==0)break;
    hand[0]--;
    n[hand[0]]++;
    rep(i,4){
      cin>>hand[1+i];
      hand[1+i]--;
      n[hand[1+i]]++;
    }
    if(n[0]&&n[1]&&n[2])
      rep(i,5)
        cout<<"3"<<endl;
    else if(n[0]==5 || n[1]==5 || n[2]==5)
      rep(i,5)
        cout<<"3"<<endl;
    else if(n[0]&&n[1])//gu choki                      
      rep(i,5)
        if(hand[i])cout<<"2"<<endl;
        else cout<<"1"<<endl;
    else if(n[0]&&n[1])//gu pa                         
      rep(i,5)
        if(hand[i])cout<<"1"<<endl;
        else cout<<"2"<<endl;
    else
      rep(i,5)
        if(hand[i]==1)cout<<"1"<<endl;
        else cout<<"2"<<endl;
  }
}