#include<iostream> 
main(){for(;;){int d[5]={},s=0,i=0;for(;i<5;i++){int h;std::cin>>h;if(!h)return 0;s|=d[i]=1<<(h-1);}for(i=0;i<5;i++){std::cout<<(s==7|s==d[i]?3:((s^d[i])==d[i]*2|(s^d[i])==d[i]/4?1:2))<<"\n";}}}