{[CT]}
const
  max_val:cardinal = 32000;
  maxn=1000;
var
  lab:array[1..maxn] of word;
  a:array[1..maxn,1..maxn] of cardinal;
  n,k:word;

procedure inp;
var
  f:text;
  i,j,c,l,br:word;
begin
  assign(f,'');
  reset(f);
  read(f,n,k);
  if n>maxn then halt;
  for l:=1 to n-1 do
  begin
   read(f,i,j,c);
   a[i,j]:=c;
   a[j,i]:=c;
  end;
  br:=1;
  for l:=1 to k do
  begin
     read(f,j);
     lab[j]:=br;
     inc(br);
  end;
  CLOSE(F);
  for i:=1 to n do
   for j:=1 to n do
    if a[i,j]=0 then a[i,j]:=max_val
end;

procedure sol;
var
   i,j,p,tem:word;
begin
   for i:=1 to n do
    for j:=1 to n do
     for p:=1 to n do
     begin
       tem:=a[j,i]+a[p,i] ;
       if a[p,j]>tem then a[p,j]:=tem;
     end;
{   for i:=1 to n do
     for j:=1 to n do
     if a[i,j]:=max_val then a[i,j]:=0;}
end;

procedure print;
var
  i,min,j,minvr:word;
begin
  for i:=1 to n do
  begin
     minvr:=0;min:=max_val;
     for j:=1 to n do
      if (a[i,j]<min)and(lab[j]<>0)and(i<>j) then
      begin
        minvr:=j;
        min:=a[i,j];
      end;
      writeln(lab[minvr],' ',min);
   end;
end;

begin
  inp;
  sol;
  print;
end.
