#include using namespace std; int main() { int n, h, m, s, a, b; cin >> n >> h >> m >> s; b = m + s * (n-1); a = h + b / 60; b = b % 60; a = a % 24; cout << a << endl << b << endl; return 0; }