#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int c[5];
    while(cin >> c[0], c[0]){
        range(i,1,5)
            cin >> c[i];
        bool rock, paper, scissors;
        rock = paper = scissors = false;
        rep(i,5){
            if(c[i] == 1){
                rock = true;
            }else if(c[i] == 2){
                scissors = true;
            }else{
                paper = true;
            }
        }
        int r, p ,s;
        if(rock && paper && scissors){
            r = p = s = 3;
        }else if(rock && paper && !scissors){
            p = 1;
            r = 2;
        }else if(rock && scissors && !paper){
            r = 1;
            s = 2;
        }else if(paper && scissors && !rock){
            s = 1;
            p = 2;
        }else if(rock){
            r = 3;
        }else if(paper){
            p = 3;
        }else if(scissors){
            s = 3;
        }
        rep(i,5){
            if(c[i] == 1)
                cout << r << endl;
            else if(c[i] == 2)
                cout << s << endl;
            else if(c[i] == 3)
                cout << p << endl;
        }
    }
}