import java.io.*; import java.util.*; class Main{ public static void main(String[] args) throws IOException{ Scanner scan=new Scanner(System.in); int n=Integer.parseInt(scan.next()); int h=Integer.parseInt(scan.next()); int m=Integer.parseInt(scan.next()); int t=Integer.parseInt(scan.next()); m+=t*(n-1); if(m>=60){ h+=m/60; m-=t*(n-1); if(h>23){ h=0; } } System.out.println(h); System.out.println(m); } }