#include #include #include #define REP(i, a, b) for (int i = int(a); i < int(b); i++) #define dump(s) cerr << __LINE__ << "\t:" << #s << " = " << (s) << endl using namespace std; int main () { long long N, H, M, T; cin >> N >> H >> M >> T; long long tm = (H * 60 + M + (N - 1) * T) % 1440; cout << tm / 60 << "\n" << tm % 60 << endl; return 0; }