#include #include #include #include #include #include #include #include #include #include #include #include #define FOR(i, a, b) for(int i=(a);i<=(b);i++) #define RFOR(i, a, b) for(int i=(a);i>=(b);i--) #define MOD 1000000007 #define INF 1000000000 using namespace std; int main(void) { int n, h, m, t; int time = 0; cin >> n >> h >> m >> t; time = h * 60 + m; time += (n - 1)*t; time %= 1440; cout << time / 60 << endl; time %= 60; cout << time << endl; return 0; }