//离线查询tarjan算法
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
const int N = 1e4 + 10, M = 2 * N + 10;
int n, m;
int h[N], e[M], ne[M], w[M], idx;
int dist[N];
int ans[M];
int st[N];
int p[N];
vector<PII> query[N];//查询 first 是 点 second 是第几次询问;
void add(int a, int b, int c)
{
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++;
}
int find(int x)
{
if (p[x] != x) p[x] = find(p[x]);
return p[x];
}
void dfs(int u, int fa)
{
for (int i = h[u]; ~i; i = ne[i])
{
int j = e[i];
if (j == fa) continue;
dist[j] = dist[u] + w[i];
dfs(j, u);
}
}
void tarjan(int u)
{
st[u] = 1;
for (int i = h[u]; ~i; i = ne[i])
{
int j = e[i];
if (!st[j])
{
tarjan(j);
p[j] = u;
}
}
for (auto item: query[u])
{
int y = item.first, id = item.second;
if (st[y] == 2)
{
int t = find(y);
ans[id] = dist[u] + dist[y] - 2 * dist[t];
}
}
st[u] = 2;
}
int main(void)
{
cin >> n >> m;
memset(h, -1, sizeof h);
for (int i = 0; i < n - 1; i ++)
{
int a, b, c;
cin >> a >> b >> c;
add(a, b, c), add(b, a, c);
}
for (int i = 0; i < m; i ++)
{
int a, b;
cin >> a >> b;
if (a != b)
{
query[a].push_back({b, i});
query[b].push_back({a, i});
}
}
for (int i = 1; i <= n; i ++) p[i] = i;
dfs(1, -1);
tarjan(1);
for (int i = 0; i < m; i ++)
cout << ans[i] << endl;
return 0;
}