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