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