#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

int main() {
    int A[5], B[5];
    while ( cin >> A[0] && A[0] ) {
        int state = 1 << A[0];
        for ( int i = 1; i < 5; ++ i ) {
            cin >> A[i];
            state |= 1 << A[i];
        }
        if ( state == ( 1 << 1 | 1 << 2 ) ) {
            for ( int i = 0; i < 5; ++ i ) {
                B[i] = A[i] == 1 ? 1 : 2;
            }
        } else if ( state == ( 1 << 2 | 1 << 3 ) ) {
            for ( int i = 0; i < 5; ++ i ) {
                B[i] = A[i] == 2 ? 1 : 2;
            }
        } else if ( state == ( 1 << 3 | 1 << 1 ) ) {
            for ( int i = 0; i < 5; ++ i ) {
                B[i] = A[i] == 3 ? 1 : 2;
            }
        } else {
            for ( int i = 0; i < 5; ++ i ) {
                B[i] = 3;
            }
        }
        for ( int i = 0; i < 5; ++ i ) {
            cout << B[i] << endl;
        }
    }
    return 0;
}