
#include<iostream>
#include<vector>
using namespace std;

int main()
{
  vector<int> p(5), r(5);
  int i, t;
  while (cin>>p[0]>>p[1]>>p[2]>>p[3]>>p[4], p[0]) {
    t = 0;
    for (i = 0; i < 5; i++) {
      if (p[i] == 3 && !(t&4)) t ^= 4;
      else if (p[i] != 3 && !(t&p[i])) t ^= p[i];
    }
    if (t == (1+2)) for (i = 0; i < 5; i++) if (p[i] == 1) r[i] = 1; else r[i] = 2;
    else if (t == (2+4)) for (i = 0; i < 5; i++) if (p[i] == 2) r[i] = 1; else r[i] = 2;
    else if (t == (4+1)) for (i = 0; i < 5; i++) if (p[i] == 3) r[i] = 1; else r[i] = 2;
    else for (i = 0; i < 5; i++) r[i] = 3;

    for (i = 0; i < 5; i++) cout<<r[i]<<endl;
  }
  return 0;
}