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()); int at=h*60+m+t*(n-1); System.out.println(at/60%24); System.out.println(at%60); } }