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