require "date"
baseDate = Date.new(2012, 12, 21)
while input = gets
	if input.chomp! == "#"
		break
	end
	input = input.split(".").map(&:to_i)
	if input.length == 3
		days = ((Date.new(input[0], input[1], input[2]) - baseDate) % (20 * 18 * 20 * 20 * 13)).to_i
		output = [days / 20 / 18 / 20 / 20, days / 20 / 18 / 20 % 20, days / 20 / 18 % 20, days / 20 % 18, days % 20]
	else
		date = baseDate + (input[4] + input[3] * 20 + input[2] * 20 * 18 + input[1] * 20 * 18 * 20 + input[0] * 20 * 18 * 20 * 20)
		output = [date.year, date.month, date.day]
	end
	puts output.join(".")
end