#include using namespace std; int main() { int n, h, m, t; cin >> n >> h >> m >> t; int time = h * 60 + m + t * (n - 1); cout << (time / 60) % 24 << "\n" << time % 60 << endl; return 0; }