#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

int main(){
    while(true){
        vector<int> te(3);
        vector<int> per(5);
        for(int i=0;i<5;i++){
            int x;
            cin >> x;
            x--;
            if(x == -1) return 0;
            te[x]++;
            per[i] = x;

        }
        if(*min_element(all(te)) > 0 or *max_element(all(te)) == 5){
            for(int i=0;i<5;i++){
                cout << 3 << endl;
            }
        }else{
            vector<char> win(5,false);
            if(te[0] > 0 and te[1] > 0){
                for(int i=0;i<5;i++){
                    if(per[i] == 0) win[i] = true;
                }
            }
            else if(te[1] > 0 and te[2] > 0){
                for(int i=0;i<5;i++){
                    if(per[i] == 1) win[i] = true;
                }
            }
            else if(te[2] > 0 and te[0] > 0){
                for(int i=0;i<5;i++){
                    if(per[i] == 2) win[i] = true;
                }
            }
            for(int i=0;i<5;i++){
                if(win[i]){
                    cout << 1 << endl;
                }else{
                    cout << 2 << endl;
                }
            }
        }
    }
    return 0;
}