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