#include <iostream>
using namespace std;

int main(){
    int h[5];
    while(cin >> h[0]){
        if(h[0] == 0) break;
        cin >> h[1] >> h[2] >> h[3] >> h[4];
        int rs[5];
        bool r = false;
        bool s = false;
        bool p = false;
        for(int i=0; i<5; ++i){
            switch(h[i]){
                case 1:
                    r = true;
                    break;
                case 2:
                    s = true;
                    break;
                case 3:
                    p = true;
            }
        }
        if(r&&s&&p)
            rs[0] = rs[1] = rs[2] = rs[3] = rs[4] = 3;
        else if((r&&!s&&!p)||(!r&&s&&!p)||(!r&&!s&&p))
            rs[0] = rs[1] = rs[2] = rs[3] = rs[4] = 3;
        else if(!r)
            for(int i=0; i<5; ++i)
                (h[i]==2)?rs[i]=1:rs[i]=2;
        else if(!s)
            for(int i=0; i<5; ++i)
                (h[i]==3)?rs[i]=1:rs[i]=2;
        else
            for(int i=0; i<5; ++i)
                (h[i]==1)?rs[i]=1:rs[i]=2;
        for(int i=0; i<5; ++i){
            cout << rs[i] << endl;
        }
    }
    return 0;
}