#!/usr/bin/ruby
#coding: utf-8

require 'date'

KI = 1
W = 20 * KI
T = 18 * W
KA = 20 * T
B = 20 * KA

n = Date.new(2012, 12, 21)

def mayan(d)
  d = d.to_i
  s = []
  s << ((d / B) % 13).to_s
  d %= B
  s << (d / KA).to_s
  d %= KA
  s << (d / T).to_s
  d %= T
  s << (d / W).to_s
  d %= W
  s << d
  s.join('.')
end

def greg(d)
end

loop do
  s = gets.chomp
  break if s =~ /#/
  if s =~ /\d*\.\d*\.\d*\.\d*\.\d*/
    b, ka, t, w, ki = s.split('.').map(&:to_i)
    puts (n + b * B + ka * KA + t * T + w * W + ki * KI).to_s.split('-').map(&:to_i).join('.')
  else
    y, m, d = s.split('.').map(&:to_i)
    puts mayan(Date.new(y, m, d) - n)
  end
end