#include <algorithm>
#include <array>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <optional>
#include <vector>

using namespace std;

int main() {
    int32_t n, h, m, t;
    cin >> n >> h >> m >> t;
    int32_t c = h * 60 + m;
    c += (n - 1) * t;
    cout << c / 60 % 24 << endl;
    cout << c % 60 << endl;
    return 0;
}