import scala.annotation.tailrec
import scala.collection.mutable

object Main extends App {

  import scala.io.StdIn._
  loop()
  @tailrec def loop(): Unit = {
    val date = readLine.trim.split('.')
    if (date.head == "#") return
    if (date.length == 3) {
      println(Maya(Gregorio(date(0).toInt, date(1).toInt, date(2).toInt).toLong - Gregorio(2012, 12, 21).toLong))
    }else {
      println(Gregorio(Maya(date(0).toInt, date(1).toInt, date(2).toInt, date(3).toInt, date(4).toInt).toLong + Gregorio(2012, 12, 21).toLong))
    }
    loop()
  }
}

object Gregorio {
  def isLeapYear(year: Int): Boolean = (year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))
  val cycle = (0 until 400).map{
    case y if isLeapYear(y) ⇒ 366L
    case _ ⇒ 365L
  }.toArray
  for (i ← cycle.indices.tail) cycle(i) += cycle(i - 1)
  val months = Array(31L, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
  for (i ← months.indices.tail) months(i) += months(i - 1)
  val monthsForLeapYear = Array(31L, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
  for (i ← monthsForLeapYear.indices.tail) monthsForLeapYear(i) += monthsForLeapYear(i - 1)
  def apply(day: Long): Gregorio = {
    val y400 = day / cycle.last
    val y = cycle.upperBound(day % cycle.last)
    make(y400.toInt * 400 + y, day % cycle.last - (if (y == 0) 0 else cycle(y - 1)))
  }
  private[this] def make(year: Int, day: Long): Gregorio = {
    val month = if (isLeapYear(year)) {
      monthsForLeapYear
    }else {
      months
    }
    val m = month.upperBound(day)
    Gregorio(year, m + 1, (day - (if (m == 0) 0 else month(m - 1)) + 1).toInt)
  }
  implicit class Wrap[T](val array: Array[T]) {
    def lowerBound(target: T)(implicit ord: Ordering[T]): Int = {
      var left = 0
      var right = array.length
      while (left < right) {
        val mid = (left + right) / 2
        if (ord.compare(array(mid), target) < 0) left = mid + 1
        else right = mid
      }
      right
    }
    def upperBound(target: T)(implicit ord: Ordering[T]): Int = {
      var left = 0
      var right = array.length
      while (left < right){
        val mid = (left + right) / 2
        if (ord.compare(array(mid), target) <= 0) left = mid + 1
        else right = mid
      }
      right
    }
  }
}
case class Gregorio(year: Int, month: Int, day: Int) {
  def toLong: Long = {
    val y400 = Gregorio.cycle.last * (year / 400)
    val y = if (year % 400 == 0) 0 else Gregorio.cycle((year % 400) - 1)
    val months = if (Gregorio.isLeapYear(year)) Gregorio.monthsForLeapYear else Gregorio.months
    y400 + y + (if (month == 1) day - 1 else (months(month - 2) + day - 1))
  }
  override def toString: String = List(year, month, day).mkString(".")
}
object Maya{
  def apply(day: Long): Maya = {
    Maya(day / (20 * 20 * 18 * 20) % 13, day / (20 * 18 * 20) % 20, day / (18 * 20) % 20, day / 20 % 18, day % 20)
  }
}
case class Maya(bactun: Long, katun: Long, tun: Long, winal: Long, kin: Long) {
  def toLong: Long = {
    (((bactun * 20 + katun) * 20 + tun) * 18 + winal) * 20 + kin
  }

  override def toString: String = List(bactun, katun, tun, winal, kin).mkString(".")
}
