def _AnnoToDaysFromZero(input)
	d = input.split(".").map(&:to_i)
	
	d[0] -= 1
	cnt = d[0] * 365 + (d[0]/4 - d[0]/100 + d[0]/400)
	
	d[0] += 1
	leap = d[0]%4==0 && (d[0]%100!=0 || d[0]%400==0)
	if d[1] > 1
		cnt += 31
	end
	if d[1] > 2
		cnt += leap ? 29 : 28
	end
	if d[1] > 3
		cnt += 31
	end
	if d[1] > 4
		cnt += 30
	end
	if d[1] > 5
		cnt += 31
	end
	if d[1] > 6
		cnt += 30
	end
	if d[1] > 7
		cnt += 31
	end
	if d[1] > 8
		cnt += 31
	end
	if d[1] > 9
		cnt += 30
	end
	if d[1] > 10
		cnt += 31
	end
	if d[1] > 11
		cnt += 30
	end
	
	cnt += d[2]
	return cnt
end
def AnnoToDays(input)
	return _AnnoToDaysFromZero(input) - _AnnoToDaysFromZero("2012.12.21")
end
def MayaToDays(input)
	d = input.split(".").map(&:to_i)
	return d[0]*20*20*18*20 + d[1]*20*18*20 + d[2]*18*20 + d[3]*20 + d[4]
end

def _DaysToAnnoFromZero(input)
	yearCnt = input/366
	
	while input > _AnnoToDaysFromZero(yearCnt.to_s + ".1.1")
		yearCnt += 1
	end
	yearCnt -= 2
	
	input -= yearCnt/4 - yearCnt/100 + yearCnt/400
	input %= 365
	
	yearCnt += 1
	leap = yearCnt%4==0 && (yearCnt%100!=0 || yearCnt%400==0)
	monthCnt = 1
	days = [31,-114514,31,30,31,30,31,31,30,31,30,31]
	days[1] = leap ? 29 : 28
	for i in 0..11
		if input > days[i]
			input -= days[i]
			monthCnt += 1
		end
	end
	
	return [yearCnt,monthCnt,input].join(".")
end
def DaysToAnno(input)
	return _DaysToAnnoFromZero(input + _AnnoToDaysFromZero("2012.12.21"))
end
def DaysToMaya(input)
	input %= 13*20*20*18*20
	d = [
		input / (20*20*18*20),
		(input % (20*20*18*20)) / (20*18*20),
		(input % (20*18*20)) / (18*20),
		(input % (18*20)) / 20,
		input % 20
	]
	return d.join(".")
end

while true
	data = gets.strip
	if data == "#"
		break
	elsif data.count(".") == 2
		puts DaysToMaya(AnnoToDays(data))
	else
		puts DaysToAnno(MayaToDays(data))
	end
end