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