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