#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(vi a(5);cin>>a[0],a[0];){
		repi(i,1,5) cin>>a[i];
		int flg=0;
		rep(i,5)
			flg|=1<<(a[i]-1);
		if(flg==7 || __builtin_popcount(flg)==1)
			rep(i,5) cout<<3<<endl;
		else if(flg==3)
			rep(i,5) cout<<(a[i]==1?1:2)<<endl;
		else if(flg==5)
			rep(i,5) cout<<(a[i]==3?1:2)<<endl;
		else if(flg==6)
			rep(i,5) cout<<(a[i]==2?1:2)<<endl;
	}
	
	return 0;
}