#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++){int k=d[i];std::cout<<(s==7|s==k?3:((s^k)==k*2|(s^k)==k/4?1:2))<<"\n";}}}