#include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> res = {
    {},
    {0,3,0,1,0,2,0,3},
    {0,0,3,2,0,0,1,3},
    {0,0,0,0,3,1,2,3}
};
int main() {
    int a[5], st;
    while (1) {
        st = 0;
        for (int i=0; i<5; ++i) {
            if (cin >> a[i] && a[i]) ; // pass
            else return 0;
            st |= 1 << (a[i] - 1);
        }
        for (int i=0; i<5; ++i) {
            cout << res[a[i]][st] << endl;
        }
    }
}