import scala.io.StdIn.{readInt,readLine}

object Main {
  def main(args:Array[String]) = {
    var n = 0
    while({n=readInt;n}!=0) {
      val a = readLine.split(" ").map(_.toInt)
      var rem = 32
      var i = 0
      while(rem!=0) {
        rem = rem - (rem-1)%5
        println(rem)
        rem = rem - (if(a(i%n)<=rem) a(i%n) else rem)
        println(rem)
        i += 1
      }
    }
  }
}