#include <cstdio>

main(){
	while(1){
		int h[5] = {0}, t[4] = {0}, w = 0;
		for(;w<5;w++){
			scanf("%d", h+w);t[h[w]]++;
			if(!*h)break;
		}
		if(!*h)break;

		if(t[1] && t[2] && t[3])
			w = -1;
		else if(t[1] && t[2])
			w = 1;
		else if(t[2] && t[3])
			w = 2;
		else if(t[1] && t[3])
			w = 3;
		else
			w = -1;

		while((*t)++<5)
			puts(w<0?"3":h[*t-1]-w?"2":"1");
	}
}