#include "bits/stdc++.h" using namespace std; #define REP(i, n) for(int i=0; i<(n); i++) int N,H,M,T; signed main() { cin >> N >> H >> M >> T; int X = H * 60 + M + T * (N - 1); int h = X / 60 % 24; int m = X % 60; cout << h << endl; cout << m << endl; return 0; }