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