#include using namespace std; int main(void) { int n,h,m,t; cin>>n>>h>>m>>t; int cur = h * 60 + m; cur += t * (n - 1); cur %= 1440; cout << cur / 60 << endl; cout << cur % 60 << endl; }