#include using namespace std; typedef long long ll; typedef pair P; const int INF = 1e9; const int mod = 1e9+7; const double EPS = 1e-10; const double PI = acos(-1.0); int main() { int n,h,m,t; cin >> n >> h >> m >> t; for(int i = 0; i < n-1; i++){ m += t; if(m >= 60){ h += m/60; m %= 60; } if(h >= 24) h %= 24; } cout << h << '\n' << m << endl; return 0; }