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