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