#!/usr/bin/perl

use strict;

my $l;
my $del;

my $from;
my $to;

$del=shift;
$del=$del*1;


sub deformat
{
	my $in=pop();
	my @ar;
	my $h;
	my $m;
	my $s;
	my $ms;

	($h, $m, $s, $ms)=split(":", join(":", split(",", $in)));

	return $ms + $s*1000 + $m*60*1000 + $h*60*60*1000;
}

sub pad
{
	my $n=pop();
	my $str=pop();

	while (length($str)<$n) {
		$str="0" . $str;
	}

	return $str;
}


sub reformat
{
	my $in=pop();
	my $h;
	my $m;
	my $s;
	my $ms;

	$ms=$in % 1000;
	$s=int($in/1000)%60;
	$m=int(int($in/1000)/60)%60;
	$h=int(int(int($in/1000)/60)/60);

	return pad($h, 2) . ":" . pad($m, 2) . ":" . pad($s, 2) . "," . pad($ms, 3);
}

sub get_times
{
	my $ln=pop();
	my $f;
	my $t;
	my @a;

	@a=split(" --> ", $ln);

	$f=deformat($a[0]);
	$t=deformat($a[1]);


	return ($f, $t);
}


sub get_formatted_line
{
	my $t=pop();
	my $f=pop();
	my $r;

	$r=reformat($f) . " --> " . reformat($t) . "\r\n";

	return $r;
}


while ($l=<STDIN>) { # dialogue number
	print $l;

	$l=<STDIN>;

	($from, $to) = get_times($l);
	$from+=$del;
	$to+=$del;
	$l=get_formatted_line($from, $to);

	print $l;

	while (($l=<STDIN>) && ($l ne "\n") && ($l ne "\r\n") ) {
		print $l;
	}
	print $l;
}

