#include using namespace std; int main(){ int N,H,M,T; cin >> N >> H >> M >> T; M=M+T*(N-1);H=(H+M/60)%24;M%=60; cout << H << endl << M << endl; return 0; }