#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	while(true){
		bool flag =true;
		map<int,int> data;
		data.clear();
		bool draw =false;
		bool goo,tyoki,pa;
		goo=tyoki=pa=false;
		int a[5]={0};
		for(int i =0;i <5;i++){
			int x;
			cin>>x;
			if(x==0){
				flag =false;
				break;
			}
			data[x]++;
			a[i]=x;
		}
		if((data[1]&&data[2]&&data[3])||(data[1]&&data[2]==0&&data[3]==0)||(
		   data[1]==0&&data[2]&&data[3]==0)||(data[1]==0&&data[2]==0&&data[3])){
			draw =true;
		}else if((data[1]&&data[2]&&data[3]==0)){
			goo =true;
		}else if((data[1]==0&&data[2]&&data[3])){
			tyoki =true;
		}else if((data[1]&&data[2]==0&&data[3])){
			pa =true;
		}
		if(draw){
			for(int i =0;i <5;i++){
				cout <<3<<endl;
			}
			continue;
		}else if(goo){
			for(int i =0;i <5;i++){
				if(a[i]==1){
					cout <<1<<endl;
				}else{
					cout <<2<<endl;
				}
			}
		}else if(tyoki){
			for(int i =0;i <5;i++){
				if(a[i]==2){
					cout <<1<<endl;
				}else{
					cout <<2<<endl;
				}
			}
		}else if(pa){
			for(int i =0;i <5;i++){
				if(a[i]==3){
					cout <<1<<endl;
				}else{
					cout <<2<<endl;
				}
			}
		}
		if(!flag)break;
	}
	return 0;
}