#include using ll = long long; using namespace std; int main() { ll n,h,m,t,tt,mm; scanf("%lld%lld%lld%lld",&n,&h,&m,&t); tt=t*(n-1); mm=(m+tt)%1440; h=(h+(m+tt)/60)%24; printf("%lld %lld\n",h,mm); return 0; }