#include using namespace std; int main() { int N, H, M, T; cin >> N >> H >> M >> T; for (int i = 1; i < N; i++) { M += T; while (M >= 60) { H++; M -= 60; } while (H >= 24) { H -= 24; } } cout << H << endl << M; return 0; }