### constant

MDAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

### subroutines

def leap?(y)
  (y % 4 == 0) && (y % 100 != 0 || y % 400 == 0)
end

def ad2days(y, m, d)
  lp = leap?(y)
  ly = y - 1
  m -= 1

  (ly * 365 + ly / 4 - ly / 100 + ly / 400) +
    $msums[m] + ((lp && m >= 2) ? 1 : 0) +
    d
end

def days2ad(days)
  y = 1
  lp = false
  ydays = 365

  while days > ydays
    days -= ydays
    y += 1
    lp = leap?(y)
    ydays = lp ? 366 : 365
  end

  m = 0

  while true
    mdays = MDAYS[m]
    mdays += 1 if m == 1 && lp
    break if days <= mdays
    days -= mdays
    m += 1
  end

  [y, m + 1, days]
end

def maya2days(b, ka, t, w, ki)
  (((b * 20 + ka) * 20 + t) * 18 + w) * 20 + ki
end

def days2maya(days)
  ki = days % 20
  days /= 20
  w = days % 18
  days /= 18
  t = days % 20
  days /= 20
  ka = days % 20
  days /= 20
  b = days % 13

  [b, ka, t, w, ki]
end

### main

$msums = [0]
(1..12).each{|m| $msums[m] = $msums[m - 1] + MDAYS[m - 1]}
#p $msums

base = ad2days(2012, 12, 21)
#p base
#exit 0

while true
  line = gets.strip
  break if line == '#'

  nums = line.split('.').map{|s| s.to_i}

  if nums.length == 3
    days = ad2days(*nums) - base
    puts days2maya(days).join('.')
  else
    days = maya2days(*nums) + base
    puts days2ad(days).join('.')
  end
end