#include #define rep(i, n) for (int i = 0; i < n; ++i) using ll = long long; using namespace std; const int INF = 1e9; const int MOD = INF + 7; int main() { ll n, h, m, t; cin >> n >> h >> m >> t; --n; ll now = h * 60 + m + t * n; now %= 1440; cout << now / 60 << endl << now % 60 << endl; return 0; }