#include<iostream>
#define rep(k,p) for(int i=k;i<p;i++)
using namespace std;int main(){int s[5],g[4];while(1){rep(0,4)g[i]=0;int n=0,v=0;rep(0,5){cin>>s[i];if(!s[i])break;if(!g[s[i]]){n++;g[s[i]]=1;if(v-1==(s[i]%3)||!v)v=s[i];}}if(!*s)break;rep(0,5)cout<<(n==2?(v==s[i]?1:2):3)<<endl;}return 0;}