//https://ncode.syosetu.com/n4830bu/296/ #include using namespace std; using ll = long long; int main() { ll N, H, M, T; cin >> N >> H >> M >> T; M += 60 * H; M += T * (N - 1); M %= 60 * 24; cout << M / 60 << endl; cout << M % 60 << endl; }