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