Program GPATHS;
type Zali=record
     i,j,l:integer;
end;
var N:3..100000;
    K:2..100000;
    c:1..100000;
    t,d,e,razst:integer;
    A:Array [1..10000] of Zali;
    B:Array [1..1000] of longint;
begin
     readln(N,K);
     for t:=1 to N-1 do
     begin
          readln(A[t].i,A[t].j,A[t].l);
     end;
     for t:=1 to K do
     readln(B[t]);
     for t:=1 to K do
         for d:=1 to N-1 do
             begin
                  if B[t]=A[d].i then
                  begin
                       Razst:=0;
                       for e:=1 to D do Razst:=A[e].l+Razst;
                       writeln(A[d].i,' ',Razst);
                  end;
                  if B[t]=A[d].j then
                  begin
                       Razst:=0;
                       for e:=1 to D do Razst:=A[e].l+Razst;
                       writeln(A[d].j,' ',Razst);
                  end;
             end;
     readln;
end.