#include<bits/stdc++.h>
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#define int long long
using namespace std;
int read(){
int s=0,w=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-')w=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
s=s*10+c-'0';
c=getchar();
}
return s*w;
}
void print(int x){
if(x<0){
putchar('-');
x=-x;
}
if(x>=10)print(x/10);
putchar(x%10+'0');
return;
}
struct Time{
int h,m,s,ms;
friend Time operator +(Time a,int b){
a.ms+=b;
while(a.ms>999){
a.ms-=1000;
a.s++;
}
while(a.ms<0){
a.ms+=1000;
a.s--;
}
while(a.s>59){
a.s-=60;
a.m++;
}
while(a.s<0){
a.s+=60;
a.m--;
}
while(a.m>60){
a.m-=60;
a.h++;
}
while(a.m<0){
a.m+=60;
a.h--;
}
return a;
}
}st[110],et[110];
int cut,id[110];
int delay;
string s[110];
signed main(){
while(1){
string ls;int f=1;
id[++cut]=read();
scanf("%lld:%lld:%lld,%lld --> %lld:%lld:%lld,%lld\r\n",
&st[cut].h,&st[cut].m,&st[cut].s,&st[cut].ms,
&et[cut].h,&et[cut].m,&et[cut].s,&et[cut].ms);
do{
if(!f)s[cut]+=ls,s[cut]+='\n';
f=0;
getline(cin,ls);
}while(ls!=""&&ls!="#");
if(ls=="#")break;
}
delay=read();
for(int i=1;i<=cut;i++){
st[i]=st[i]+delay;
et[i]=et[i]+delay;
print(id[i]);putchar('\n');
printf("%02lld:%02lld:%02lld,%03lld --> %02lld:%02lld:%02lld,%03lld\n",
st[i].h,st[i].m,st[i].s,st[i].ms,
et[i].h,et[i].m,et[i].s,et[i].ms);
cout<<s[i];
if(i==cut)putchar('#');
else putchar('\n');
}
return 0;
}