//04
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  for(;;){
    int h[5];
    int k[4]={};
    for(int i=0;i<5;i++){
      cin>>h[i];
      if(h[i]==0)return 0;
      k[h[i]]=1;
    }
    if(count(k,k+4,1)!=2){
      for(int i=0;i<5;i++){
	cout<<3<<endl;
      }
    }else{
      int n=find(k+1,k+4,0)-k;
      for(int i=0;i<5;i++){
	cout<<((n%3+1==h[i])?1:2)<<endl;
      }
    }
  }
  return 0;
}
      