var g:array [0..500,0..500] of longint;
a,b,c,i,k,j,l,v,s,n,t,t1,t2,t3,t4,tt:integer;
str,strr:string;
begin
readln(str);
readln(n,k);
for i:=0 to n do
for j:=0 to n do
g[i,j]:=900000000;
for i:=1 to k do
begin readln(a,b,c);
g[a,b]:=c;
g[b,a]:=c;
end;
readln(strr);
s:=1;
t:=0;
while ord(strr[s])-48<=9 do inc(s);
for i:=1 to s-1 do
begin v:=1;
for j:=1 to s-i-1 do
v:=v*10;
t:=t+v*(ord(strr[i])-48);
end;
case strr[s] of
’h’:t:=t*60;
’s’:if t<>0 then t:=1;
end;
for l:=0 to n do
for i:=0 to n do
if i<>l then for j:=0 to n do
if (i<>j) and (j<>l) and (g[i,l]+g[j,l]<g[i,j]) then begin g[i,j]:=g[i,l]+g[j,l];
g[j,i]:=g[i,j];
end;
t:=t+g[1,n];
t1:=(ord(str[1])-48)*10+ord(str[2])-47;
t2:=(ord(str[4])-48)*10+ord(str[5])-48;
t2:=60-t2;
tt:=(24-t1)*60+t2;
if tt<=t then write(’Sad’)
else begin t3:=t div 60;
t4:=t-t3*60;
t1:=t1-1+t3;
t2:=60-t2+t4;
if t2>60 then begin inc(t1);
t2:=t2-60;
end;
write(t1,’:’);
if t2<10 then write(’0’,t2)
else write(t2);
end;
end.