#include <bits/stdc++.h>
using namespace std;

int main() {
    while (true) {
        int h1;
        cin >> h1;
        
        if (h1==0) {
            break;
        }
        
        int h2, h3, h4, h5;
        cin >> h2 >> h3 >> h4 >> h5;
        
        int l[5] = {h1, h2, h3, h4, h5};
        set<int> s{h1, h2, h3, h4, h5};
        
        if (s.find(1)!=s.end() && s.find(2)!=s.end() && s.find(3)!=s.end()) {
            for (int i=0; i<5; i++) {
                cout << 3 << endl;
            }
        }
        else if (s.find(1)!=s.end() && s.find(2)!=s.end()) {
            for (int i=0; i<5; i++) {
                if (l[i]==1) {
                    cout << 1 << endl;
                }
                else {
                    cout << 2 << endl;
                }
            }
        }
        else if (s.find(2)!=s.end() && s.find(3)!=s.end()) {
            for (int i=0; i<5; i++) {
                if (l[i]==2) {
                    cout << 1 << endl;
                }
                else {
                    cout << 2 << endl;
                }
            }
        }
        else if (s.find(3)!=s.end() && s.find(1)!=s.end()) {
            for (int i=0; i<5; i++) {
                if (l[i]==3) {
                    cout << 1 << endl;
                }
                else {
                    cout << 2 << endl;
                }
            }
        }
        else {
            for (int i=0; i<5; i++) {
                cout << 3 << endl;
            }
        }
    }
}
