import java.util.Scanner; public class Main{ public static void main(String[] args) { Main main=new Main(); main.run(); } void run() { Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int H=sc.nextInt(); int M=sc.nextInt(); int T=sc.nextInt(); int time=(N-1)*T; int res=H*60+M+time; System.out.println((res/60)%24); System.out.println(res%60); } }