#include <iostream>
#define rep(i) for(i=0;i<5;i++)
using namespace std;
int main(){
  int a[5],i;
  while(cin>>a[0],a[0]){
    int b[3]={0};
    b[a[0]-1]++;
    for(i=1;i<5;i++){
      cin>>a[i];
      b[a[i]-1]++;
    }
    if(b[0]&&b[1]&&!b[2])rep(i)cout<<((a[i]==1)?1:2)<<endl;
    else if(b[0]&&!b[1]&&b[2])rep(i)cout<<((a[i]==3)?1:2)<<endl;
    else if(!b[0]&&b[1]&&b[2])rep(i)cout<<((a[i]==2)?1:2)<<endl;
    else rep(i)cout<<'3'<<endl;
  }
}