#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); ll N,H,M,T; cin >> N >> H >> M >> T; ll tmp = H * 60 + M + T * (N - 1); cout << (tmp / 60) % 24 << endl; cout << tmp % 60 << endl; }