#include using namespace std; int main() { int n,h,m,t; cin >> n >> h >> m >> t; m += t * (n-1); if(m >= 60){ h += m / 60; m %= 60; } if(h >= 24) h %= 24; cout << h << '\n' << m << endl; return 0; }