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