h,m = map(int,input().split())
if(m<45):
if(h<1):
h=23
m = (m+60)-45
else:
h -= 1
m = (m+60)-45
else:
m -= 45
print(h,m)
h,m = map(int,input().split())
if(m<45):
if(h<1):
h=23
m = (m+60)-45
else:
h -= 1
m = (m+60)-45
else:
m -= 45
print(h,m)