import scala.math._

object Main {
  val sc = new java.util.Scanner(System.in)
  def main(args: Array[String]) {
    while(true) {
      val a = new Array[Int](5)
      a(0) = sc.nextInt()
      if(a(0) == 0) {
        return
      }

      for(i <- 1 until 5) {
        a(i) = sc.nextInt()
      }
      val b = a.toSet match {
        case s if s == Set(1,2,3) => Map(1 -> 3, 2 -> 3, 3 -> 3)
        case s if s == Set(1) => Map(1 -> 3, 2 -> 3, 3 -> 3)
        case s if s == Set(2) => Map(1 -> 3, 2 -> 3, 3 -> 3)
        case s if s == Set(3) => Map(1 -> 3, 2 -> 3, 3 -> 3)
        case s if s == Set(1,2) => Map(1 -> 1, 2 -> 2)
        case s if s == Set(2,3) => Map(2 -> 1, 3 -> 2)
        case s if s == Set(3,1) => Map(3 -> 1, 1 -> 2)
      }
      a.map(b).foreach(println)
    }
  }
}