#include int main(void){ int N, H, M, T; scanf("%d%d%d%d", &N, &H, &M, &T); M += ( N - 1) * T; while (M >= 60){ M -= 60; H++; } while (H >= 24){ H -=24; } printf ("%d\n%d\n", H, M); return 0; }