#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll; 
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;

int a[5];

int main(){
	while (1){
		bool f[5] = {};
		REP(i, 5){
			cin >> a[i];
			if (!a[i])return 0;
			f[a[i]] = 1;
		}
		if ((f[1] && f[2] && f[3]) || (f[1] && !f[2] && !f[3]) || (!f[1] && f[2] && !f[3])
			|| (!f[1] && !f[2] && f[3])){
			REP(i, 5){
				cout << 3 << endl;
			}
			continue;
		}
		REP(i, 5){
			if (!f[2]){
				a[i] = (a[i] + 1) % 3;
			}
			else if (!f[1]){
				a[i]--;
			}
			cout << a[i] << endl;
		}
	}
}