/** * author: boutarou * created: 02.08.2020 12:17:10 **/ #include using namespace std; #define rep(i,n) for(int i = 0; i < int(n); i++) using ll = long long; using P = pair; int main() { ll n, h, m, t; cin >> n >> h >> m >> t; ll ans = h * 60 + m; ans += (n - 1) * t; cout << (ans / 60) % 24 << endl << ans % 60 << endl; return 0; }