a,b,c,d = map(int,input().split()) c += (a-1)*d while c > 59: c -= 60 b += 1 print(b) print(c)