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