#include using namespace std; int main() { int N,H,M,T; scanf("%d %d %d %d",&N,&H,&M,&T); int m=H*60+M+T*(N-1); printf("%d\n%d\n",m/60%24,m%60); }