#include #include #include #include #include #define all(x) x.begin(),x.end() #define pb push_back #define ll long long #define P pair #define LP pair using namespace std; int main() { ll n,h,m,t,cnt; cin >>n>>h>>m>>t; cnt = h*60+m+t*(n - 1); cout << cnt/ 60 % 24 << endl; cout << cnt% 60 << endl; return 0; }