#include <bits/stdc++.h>

using namespace std;

int main()
{
    
    while (1) {
        vector<int> DataBase;

        for (int i = 0; i < 5; ++i) {
            int data;
            cin >> data;
            if (data == 0) break;
            DataBase.push_back(data);
        }

        if (DataBase.size() == 0) {
            break;
        }

        bool win_stone = false;
        bool win_sissor = false;
        bool win_paper = false;
        bool aiko = false;

        win_stone = static_cast<bool>(find(DataBase.begin(), DataBase.end(), 1) != DataBase.end() &&
                                        find(DataBase.begin(), DataBase.end(), 2) != DataBase.end() &&
                                        find(DataBase.begin(), DataBase.end(), 3) == DataBase.end());

        win_sissor = static_cast<bool>(find(DataBase.begin(), DataBase.end(), 1) == DataBase.end() &&
                                        find(DataBase.begin(), DataBase.end(), 2) != DataBase.end() &&
                                        find(DataBase.begin(), DataBase.end(), 3) != DataBase.end());
        win_paper = static_cast<bool>(find(DataBase.begin(), DataBase.end(), 1) != DataBase.end() &&
                                        find(DataBase.begin(), DataBase.end(), 2) == DataBase.end() &&
                                        find(DataBase.begin(), DataBase.end(), 3) != DataBase.end());
        aiko = static_cast<bool>(find(DataBase.begin(), DataBase.end(), 1) != DataBase.end() &&
                                        find(DataBase.begin(), DataBase.end(), 2) != DataBase.end() &&
                                        find(DataBase.begin(), DataBase.end(), 3) != DataBase.end());
        
        vector<int> ResultBase(5, 0);

        if (win_stone) {
            for (int i = 0; i < static_cast<int>(DataBase.size()); ++i) {
                switch(DataBase[i]) {
                    case 1:
                        ResultBase[i] = 1;
                        break;
                    case 2:
                        ResultBase[i] = 2;
                        break;
                    default:
                        break;
                }
            }
        }

        if (win_sissor) {
            for (int i = 0; i < static_cast<int>(DataBase.size()); ++i) {
                switch(DataBase[i]) {
                    case 2:
                        ResultBase[i] = 1;
                        break;
                    case 3:
                        ResultBase[i] = 2;
                        break;
                    default:
                        break;
                }
            }
        }

        if (win_paper) {
            for (int i = 0; i < static_cast<int>(DataBase.size()); ++i) {
                switch(DataBase[i]) {
                    case 3:
                        ResultBase[i] = 1;
                        break;
                    case 1:
                        ResultBase[i] = 2;
                        break;
                    default:
                        break;
                }
            }
        }

        if (aiko) {
            for (int i = 0; i < static_cast<int>(DataBase.size()); ++i) {
                 ResultBase[i] = 3;
             }
        }
        
        for (int i = 0; i < static_cast<int>(ResultBase.size()); ++i) {
            cout << ResultBase[i] << endl;
        }
    }

    return 0;
}