https://www.acmicpc.net/problem/2852
n=int(input())
score1 = 0; m1 = 0; s1 = 0; sum1m = 0; sum1s = 0
score2 = 0; m2 = 0; s2 = 0; sum2m = 0; sum2s = 0
for i in range(n):
a=list(input().split())
k=int(a[0])
ar=a[1].split(':')
m=int(ar[0])
s=int(ar[1])
if k==1:
if score1==score2:
m1=m
s1=s
score1+=1
if score1==score2:
if s>=s2:
sum2m+=m-m2
sum2s+=s-s2
else:
sum2m+=m-m2-1
sum2s+=s-s2+60
else:
if score1==score2:
m2=m
s2=s
score2+=1
if score1==score2:
if s>=s1:
sum1m+=m-m1
sum1s+=s-s1
else:
sum1m+=m-m1-1
sum1s+=s-s1+60
sum1m+=sum1s//60; sum1s=sum1s%60
sum2m+=sum2s//60; sum2s=sum2s%60
if score1>score2:
sum1m+=47-m1
sum1s+=60-s1
elif score1<score2:
sum2m+=47-m2
sum2s+=60-s2
sum1m+=sum1s//60; sum1s=sum1s%60
sum2m+=sum2s//60; sum2s=sum2s%60
print("%02d:%02d"%(sum1m,sum1s))
print("%02d:%02d"%(sum2m,sum2s))