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