#include<stdio.h>

int main(void){
  int a[5],i;
  while(scanf("%d",&a[0]),a[0]!=0){
    int used[3];
    used[0]=used[1]=used[2]=0;
    used[a[0]-1]=1;
    for(i=1;i<5;i++)scanf("%d",&a[i]),used[a[i]-1]=1;
    int sum=used[0]+used[1]+used[2];
    printf("%d\n",sum);
    if(sum!=2){
      for(i=0;i<5;i++)printf("3\n");
      continue;
    }
    for(i=0;i<5;i++){
      switch(a[i]){
      case 1:
	if(used[1])printf("1\n");
	else printf("2\n");
	break;
      case 2:
	if(used[2])printf("1\n");
	else printf("2\n");
	break;
      case 3:
	if(used[0])printf("1\n");
	else printf("2\n");
	break;
      }
    }
  }
}