n,h,m,t = map(int,input().split()) mn = h * 60 + m mn += t * (n - 1) mn %= 24 * 60 print(mn // 60) print(mn % 60)