#include int main(){ int n,h,m,t,o,h2,h3,m3; scanf("%d%d%d%d",&n,&h,&m,&t); o = m + t*n - t; h2 = o/60; h3 = h + h2; h3 %= 24; m3 = o - h2*60; printf("%d\n%d",h3,m3); }