#include <iostream>

using namespace std;

int main() {
	int human[5];
	while (cin >> human[0], human[0]) {
		for (int i = 1; i < 5; ++i)
			cin >> human[i];
		
		int hands[3] = {0};
		for (int i = 0; i < 5; ++i)
			hands[human[i]-1] = 1;
		
		int k = 0, no = 0;
		for (int i = 0; i < 3; ++i)
			if (hands[i]) ++k;
			else no = i + 1;
		
		if (k == 2) {
			no = (no + 1) % 3 + 1;
			for (int i = 0; i < 5; ++i)
				if (human[i] == no) cout << "2" << endl;
				else cout << "1" << endl;
		}
		else
			for (int i = 0; i < 5; ++i)
				cout << "3" << endl;
	}
}