#include int main(void){ int N,H,M,T,LastH,LastM; scanf("%d",&N); scanf("%d",&H); scanf("%d",&M); scanf("%d",&T); LastH=(H+((N-1)*T+M)/60)%24; LastM=(T*(N-1)+M)%60; printf("%d\n",LastH); printf("%d\n",LastM); return 0; }