#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        vector<int> a(5);
        vector<int> b(4);
        for(int i=0; i<5; ++i){
            cin >> a[i];
            if(a[i] == 0)
                return 0;
            ++ b[a[i]];
        }

        if(b[1] == 5 || b[2] == 5 || b[3] == 5 || (b[1] > 0 && b[2] > 0 && b[3] > 0)){
            a.assign(5, 3);
        }else{
            if(b[1] == 0){
                replace(a.begin(), a.end(), 2, 1);
                replace(a.begin(), a.end(), 3, 2);
            }else if(b[2] == 0){
                replace(a.begin(), a.end(), 1, 2);
                replace(a.begin(), a.end(), 3, 1);
            }
        }

        for(int i=0; i<5; ++i)
            cout << a[i] << endl;
    }
}