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