#include using namespace std; typedef long long ll; typedef pair P; const int INF = 1e9; const int mod = 1e9+7; const double EPS = 1e-10; const double PI = acos(-1.0); int main() { int n,h,m,t; cin >> n >> h >> m >> t; ll res = h*60+m; res += t*(n-1); cout << res%(24*60)/60 << '\n' << res%60 << endl; return 0; }