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