import java.util.Scanner; class no296{ public static void main(String[] args) { Scanner stdIn=new Scanner(System.in); int n,h,m,t; n=stdIn.nextInt(); h=stdIn.nextInt(); m=stdIn.nextInt(); t=stdIn.nextInt(); h=h*60+m+t*--n; System.out.print(h/60%24+"\n"+h%60); } }