program GRAPHS;

var Graph:array[1..100000,1..100000] of LongInt;
    Zali:array[1..100000] of LongInt;
    m,N,K,closest:LongInt;

procedure Init;
var v,I,J,C,tmp:integer;
begin
 FillChar(Graph,SizeOf(Graph),0);
 FillChar(Zali,SizeOf(Zali),0);
 readln(N,K);
 for v:=1 to N-1 do begin
  readln(I,J,C);
  Graph[I,J]:=C;
  Graph[J,I]:=C;
 end;
 for v:=1 to K do begin
  readln(tmp);
  Zali[v]:=tmp;
 end;
end;

function IsZala(n:LongInt):LongInt;
var v:integer;
    EsGibt:LongInt;
begin
 EsGibt:=0;
 for v:=1 to K do
  If (Zali[v]=n) then EsGibt:=v;
 IsZala:=EsGibt;
end;

procedure GetNextZala(j:LongInt);
var i:LongInt;
begin
 If (closest<>0) and (IsZala(j)<>0) then begin
  writeln(IsZala(j),closest);
 end else begin
  for i:=1 to N do begin
   If (Graph[n,i]>0) then begin
    closest:=closest+Graph[n,i];
    GetNextZala(i);
   end;
  end;
 end;
end;

begin
 Init;
 for m:=1 to K do begin
  closest:=0;
  GetNextZala(Zali[m]);
 end;
end.
