#include <iostream>
using namespace std;

int main() {
	int hand[5];
	while(cin >> hand[0], hand[0]) {
		for(int i = 1; i < 5; i++)
			cin >> hand[i];

		int win[5] = {-1,-1,-1,-1,-1};
		bool flg = true;
		for(int i = 0; i < 5; i++) {
			for(int j = 0; j < 5; j++) {
				if(i != j) {
					int tmp = (hand[j] - hand[i] + 3) % 3;
					if(win[i] == -1 && tmp != 0)
						win[i] = tmp;
					else if(win[i] != tmp && tmp != 0)
						flg = false;
				}
			}
		}

		if(flg) {
			for(int i = 0; i < 5; i++)
				cout << (win[i] == 0 ? 3 : win[i]) << endl;
		}
		else {
			for(int i = 0; i < 5; i++)
				cout << 3 << endl;
		}
	}
}