#include <iostream>
#include <cstring>
using namespace std;

int main(){
    int data[4],n[5];
    while(1){
        memset(data,0,sizeof(data));
        cin >> n[0];
        if(n[0] == 0) break;
        for(int i=1;i<5;i++){
            cin >> n[i];
            data[n[i]] = 1;
        }
        if((data[1] == 1 && data[2] == 1 && data[3] == 1) || (data[1] == 1 && data[2] == 0 && data[3] == 0) || (data[1] == 0 && data[2] == 1 && data[3] == 0) || (data[1] == 0 && data[2] == 0 && data[3] == 1)){
            for(int i=0;i<5;i++) cout << 3 << endl;
        }
        else if(data[1] == 1 && data[2] == 1){
            for(int i=0;i<5;i++){
                if(n[i] == 1) cout << 1 << endl;
                else cout << 2 << endl;
            }
        }
        else if(data[2] == 1 && data[3] == 1){
            for(int i=0;i<5;i++){
                if(n[i] == 2) cout << 1 <<endl;
                else cout << 2 <<endl;
            }
        }
        else if(data[1] == 1 && data[3] == 1){
            for(int i=0;i<5;i++){
                if(n[i] == 1) cout << 2 << endl;
                else cout << 1 << endl;
            }
        }
    }
}