import sys
def all_times(t):
h0,h1,m0,m1=t[0],t[1],t[3],t[4]
hh=[h for h in range(24) if (h0=='?' or h0==f'{h:02d}'[0])
and (h1=='?' or h1==f'{h:02d}'[1])]
mm=[m for m in range(60) if (m0=='?' or m0==f'{m:02d}'[0])
and (m1=='?' or m1==f'{m:02d}'[1])]
return [h*60+m for h in hh for m in mm]
def solve():
t1=sys.stdin.readline()
t2=sys.stdin.readline()
times1=all_times(t1)
times2=all_times(t2)
#双指针
min_diff=10**9
i=0
j=0
while i<len(times1) and j<len(times2):
if times1[i]>=times2[j]:
j+=1
else:
min_diff=min(min_diff,times2[j]-times1[i])
i+=1
max_diff=times2[-1]-times1[0] #由于都是升序排列
print(min_diff, max_diff)
if __name__=='__main__':
solve()