#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for(int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    vector<int> h(5);
    while(cin >> h[0] && h[0])
    {
        REP(i, 1, 5) cin >> h[i];

        set<int> s;

        rep(i, 5) s.insert(h[i]);

        if(!s.count(1) && s.count(2) && s.count(3))
        {
            rep(i, 5)
            {
                cout << (h[i] == 2 ? 1 : 2) << endl;
            }
        }
        else if(!s.count(2) && s.count(1) && s.count(3))
        {
            rep(i, 5)
            {
                cout << (h[i] == 3 ? 1 : 2) << endl;
            }
        }
        else if(!s.count(3) && s.count(1) && s.count(2))
        {
            rep(i, 5)
            {
                cout << (h[i] == 1 ? 1 : 2) << endl;
            }
        }
        else
        {
            cout << 3 << endl;
        }
    }

    return 0;
}
