{$M 4000000000}
const maxn = 1000;
      fi = '';
      fo = '';
      oo = 1000000000;
type node = record
              num: word;
              x: array[1..maxn] of word;
              c: array[1..maxn] of word;
            end;
var n,q: word;
    a: array[1..maxn] of node;
procedure enter;
var i,u,v,cap:word;
begin
  assign(input,fi);
  reset(input);
  readln(n,q);
  for i:=1 to n-1 do
  begin
    readln(u,v,cap);
    with a[u] do
    begin
      inc(num);
      x[num]:=v;
      c[num]:=cap;
    end;
    with a[v] do
    begin
      inc(num);
      x[num]:=u;
      c[num]:=cap;
    end;
  end;
end;

procedure solve;
var i,u,v:word;
    len: longint;
    visit: array[1..maxn] of boolean;
procedure dfs(i:word);
var j:word;
begin
  visit[i]:=true;
  if i=v then writeln(len)
  else
  with a[i] do
  for j:=1 to num do
  if not (visit[x[j]]) then
  begin
    len:=len+c[j];
    dfs(x[j]);
    len:=len-c[j];
  end;
end;
begin
  assign(output,fo);
  rewrite(output);
  for i:=1 to q do
  begin
    fillchar(visit,sizeof(visit),false);
    readln(u,v);
    len:=0;
    dfs(u);
  end;
  close(output);
  close(input);
end;
begin
  enter;
  solve;
end.
