dc = 0
while(True):
try:
dc += 1
n = int(input())
data = [[0, 600]] + [ [sum([int(s) if idx else int(s)*60 for idx, s in enumerate(_.split(":"))]) for _ in input().split()[:2] ] for i in range(n) ] + [[1080, 0]]
length = sorted([[data[i][0] - data[i-1][1], data[i-1][1]] for i in range(1, len(data))], key=lambda x:(x[0], -x[1]), reverse=True)
sh, sm, dh, dm = length[0][1]//60, length[0][1]%60, length[0][0]//60, length[0][0]%60
print(f"Day #{dc}: the longest nap starts at {sh:0>2}:{sm:0>2} and will last for " + (f"{dh} hours and " if dh else "") + f"{dm} minutes.")
except EOFError:
break