#include"bits/stdc++.h" using namespace std; int main() { int n, h, w; long m; cin >> n >> h >> m >> w; m += (n - 1)*w; cout << (h + m / 60)%24 << endl; cout << m % 60 << endl; }