#include using namespace std; int main(){ int a,b,c,d;cin>>a>>b>>c>>d; c+= (a-1)*d; b += c/60; cout << b%24 << endl; cout << c%60 << endl; }