#include using namespace std; int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int n, h, m, t; cin >> n >> h >> m >> t; int x = h * 60 + m; for (int i = 0; i < n - 1; ++i) { x += t; x %= 1440; } cout << x / 60 << "\n" << x % 60 << endl; return 0; }