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