#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int t;
	while(cin >> t && t)
	{
		vector<int> v;
		v.push_back(t);

		rep(i,4)
		{
			cin >> t;
			v.push_back(t);
		}
		
		map<int,int> m;
		rep(i,5)
		{
			m[v[i]]++;
		}

		if(m.size() >= 3 || m.size() == 1)
		{
			rep(i,5) cout << 3 << endl;
		}
		else
		{
			if(m[1] > 0 && m[2] > 0)
			{
				rep(i,5)
				{
					if(v[i] == 1) cout << 1 << endl;
					else cout << 2 << endl;
				}
			}
			else if(m[2] > 0 && m[3] > 0)
			{
				rep(i,5)
				{
					if(v[i] == 2) cout << 1 << endl;
					else cout << 2 << endl;
				}
			}
			else if(m[1] > 0 && m[3] > 0)
			{
				rep(i,5)
				{
					if(v[i] == 3) cout << 1 << endl;
					else cout << 2 << endl;
				}
			}
		}
	}
	return 0;
}