import java.util.Scanner; class C{ public static void main(String[]$){ Scanner s=new Scanner(System.in); long n=s.nextInt(),h=s.nextInt(),m=s.nextInt(),t=s.nextInt(),r=h*60+m+t*(n-1); System.out.println(r%1440/60+"\n"+r%60); } }