import java.util.*;
import java.text.*;
import java.io.*;
import java.lang.reflect.*;

public class main {
        public static void main (String [] args) {
		String linia;
		int suma;

//		System.out.println(Array.getLength(args));

		try {
		if (args[0].equals("--help") || args[0].equals("-h") || Array.getLength(args)!=2) {
			throw new ArrayIndexOutOfBoundsException();
		}

                BufferedReader fit=new BufferedReader(new FileReader(args[0]));
		

		suma=Integer.parseInt(args[1]);	
		while ((linia=fit.readLine())!=null) {
			if (esHora(linia)) {
				linia=SumaTemps(linia,suma);
			}
			System.out.println(linia);
		}		

		fit.close();
		}
		catch (IOException e) {
			System.err.println("Error llegint fitxer: "+ args[0]);

		}
		catch (ArrayIndexOutOfBoundsException e) {
			System.err.println("Ús: java subtitul fitxer.sub offset");
		}
		catch (NumberFormatException e) {
			System.err.println("El segon paràmetre ha de ser un enter");
		}


	}
	private static boolean esHora(String linia) {
		int i=0;
		boolean ret=false;

		while ((i+3<linia.length())&&!ret) {
			if (linia.charAt(i)=='-' && linia.charAt(i+1)=='-' && linia.charAt(i+2)=='>') {
					ret=true;
			}
			i++;
		}
		return ret;
	}

	private static String SumaTemps (String linia,int suma) {
		String s="";
		int a[]=new int[1];

		Calendar cal=new GregorianCalendar();
		a[0]=0;
		cal.set(Calendar.HOUR,agafa(linia,a));
		cal.set(Calendar.MINUTE,agafa(linia,a));
		cal.set(Calendar.SECOND,agafa(linia,a));

		cal.add(Calendar.SECOND,suma);
		a[0]=salta(linia,a[0]);		//per la ,
		
		s=cal.get(Calendar.HOUR)+":"+cal.get(Calendar.MINUTE)+":"+cal.get(Calendar.SECOND)+','+agafa(linia,a);

		//System.out.print("OUT: " + cal.get(Calendar.HOUR)+":"+cal.get(Calendar.MINUTE)+":"+cal.get(Calendar.SECOND)+','+agafa(linia,a));
		a[0]=salta(linia,a[0]);

                cal.set(Calendar.HOUR,agafa(linia,a));
                cal.set(Calendar.MINUTE,agafa(linia,a));
                cal.set(Calendar.SECOND,agafa(linia,a));
 
                cal.add(Calendar.SECOND,suma);

		a[0]=salta(linia,a[0]);         //per la ,
                //System.out.println("OUT: " + cal.get(Calendar.HOUR)+":"+cal.get(Calendar.MINUTE)+":"+cal.get(Calendar.SECOND)+','+agafa(linia,a));
                a[0]=salta(linia,a[0]);
		
		s+=" --> " + cal.get(Calendar.HOUR)+":"+cal.get(Calendar.MINUTE)+":"+cal.get(Calendar.SECOND)+','+agafa(linia,a);

		return (s);

	}

	private static int agafa (String linia, int[]a) {
		StringBuffer b=new StringBuffer();

		while (a[0]<linia.length() && (linia.charAt(a[0])<='9' && linia.charAt(a[0])>='0')) {
			//System.out.println("Afegit: " + linia.charAt(a[0]));
			b.append(linia.charAt(a[0]));
			a[0]++;
		}
		a[0]=salta(linia,a[0]);

		String s=b.toString();	
		//System.out.println("agafa:" +s);
		return (Integer.parseInt(s));
	}

	private static int salta (String linia, int a) {
		while  (a<linia.length() && (linia.charAt(a)>'9' || linia.charAt(a)<'0')) { 
			a++;
		}
	
		return a;


	}

}
