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

int five[5];
const int winner[4][2] = {{0, 0}, {2, 3}, {3, 1}, {1, 2}};

int main() {
	while(1) {
		cin >> five[0];
		if(!five[0]) break;
		for(int i = 1; i < 5; ++i) {
			cin >> five[i];
		}

		int f[4];
		memset(f, 0, sizeof f);
		for(int i = 0; i < 5; ++i) {
			int t = five[i];
			f[t]++;
		}
		if(f[1] && f[2] && f[3]) {
			for(int i = 0; i < 5; i++) {
				cout << 3 << endl;
			}
			goto NEXT;
		}
		for(int i = 1; i <= 3; ++i) {
			if(f[i] == 5) {
				for(int j = 0; j < 5; ++j) {
					cout << 3 << endl;

				}
				goto NEXT;
			}
		}
		for(int i = 1; i <= 3; ++i) {
			if(f[i] == 0) {
				for(int j = 0; j < 5; ++j) {
					if(winner[i][0] == five[j]) {
						cout << 1 << endl;
					} else {
						cout << 2 << endl;
					}
				}
			}
		}
		NEXT:
		;
	}
	return 0;
}