
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  while(true){
    int people[5];
    int kind[3] = {0};

    REP(i,5){
      if((people[i] = getInt()) == 0) return 0;
      kind[people[i]-1]++;
    }

    bool aiko = false;

    if(kind[0] > 0 && kind[1] > 0 && kind[2] > 0)
      aiko = true;
    if(kind[0] == 5 || kind[1] == 5 || kind[2] == 5)
      aiko = true;

    if(aiko){
      REP(i,5) print(3);
    }else{
      int kati;
      if(kind[0] == 0) kati = 2;
      if(kind[1] == 0) kati = 3;
      if(kind[2] == 0) kati = 1;

      REP(i,5) if(people[i] == kati)
        print(1);
      else
        print(2);
    }
  }
}