#include <iostream>
using namespace std;

int main() {
  int a[5],b[5],rock=0,paper=0,scissors=0;
  while(cin >> a[0],a[0]) {
    cin >> a[1] >> a[2] >> a[3] >> a[4];
    rock=0;paper=0;scissors=0;
    for(int i=0;i<5;i++) {
      if(a[i] == 1) rock++;
      else if(a[i] == 2) scissors++;
      else if(a[i] == 3) paper++;
    }

    if(rock >= 1 && scissors >= 1 && paper >= 1) {
      for(int i=0;i<5;i++) {
	b[i] = 3;
      }
    }

    else if(rock == 5 || scissors == 5 || paper == 5) {
      for(int i=0;i<5;i++) {
	b[i] = 3;
      }
    }
    else if(paper == 0) {
      for(int i=0;i<5;i++) {
	if(a[i] == 1) {
	  b[i] = 1;
	}
	else {
	  b[i] = 2;
	}
      }
    }
    else if(rock == 0) {
      for(int i=0;i<5;i++) {
	if(a[i] == 2) {
	  b[i] = 1;
	}
	else {
	  b[i] = 2;
	}
      }
    }
    else if(scissors == 0) {
      for(int i=0;i<5;i++) {
	if(a[i] == 3) {
	  b[i] = 1;
	}
	else {
	  b[i] = 2;
	}
      }
    }

    for(int i=0;i<5;i++) {
      cout << b[i] << endl;
    }
  }
}