#include using namespace std; int main(){ int N, H, M, T; cin >> N >> H >> M >> T; int T2 = H * 60 + M + T * (N - 1); cout << T2 % 1440 / 60 << endl; cout << T2 % 60 << endl; }