#include #define FOR(i,a,b) for(int i = (a); i < (b); ++i) #define REP(i,n) FOR(i,0,n) #define SZ(n) (int)(n).size() #define ALL(n) (n).begin(), (n).end() using namespace std; typedef long long LL; typedef vector VI; int main() { int n, h, m, t; cin >> n >> h >> m >> t; int ah, am, d; d = h * 60 + m + (n - 1) * t; if (d >= 1440) t -= 1440; ah = d / 60; am = d % 60; cout << ah << '\n' << am << endl; return 0; }