#! /usr/bin/env ruby
# coding: utf-8
require 'date'
D = [144000, 7200, 360, 20, 1]

while s = gets do
  v = s.scan(/\d+/).map(&:to_i)
  if v.size == 3 then
    a = []
    d = Date.new(v[0], v[1], v[2]).jd - Date.new(2012, 12, 21).jd
    D.each do |n|
      a << d / n
      d %= n
    end
    a[0] %= 13
    puts a.join(".")
  elsif v.size == 5 then
    d = 0
    D.each.with_index do |n, i|
      d += n * v[i]
    end
    dt = Date.new(2012, 12, 21) + d
    puts [dt.year, dt.month, dt.day].join(".")
  end
end