### constant

WL_TABLE = [
  [3, 3, 3],    # GCP: 000
  [3, 3, 3],    # GCP: 100
  [3, 3, 3],    # GCP: 010
  [1, 2, 0],    # GCP: 110
  [3, 3, 3],    # GCP: 001
  [2, 0, 1],    # GCP: 101
  [0, 1, 2],    # GCP: 011
  [3, 3, 3],    # GCP: 111
]

### main

while true
  k = gets.strip.to_i
  break if k == 0

  members = [k - 1]

  4.times.each do
    members << (gets.strip.to_i - 1)
  end

  wl = 0
  for h in members
    wl |= 1 << h
  end

  wlt = WL_TABLE[wl]

  for h in members
    puts wlt[h]
  end
end