#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
typedef pair<int, int> PII;
const int N = 10010, M = 20010;
// 2号点:代表已经访问并结束回溯
// 1号点:代表正在访问
// 0号点:代表还没有访问过
int n, m;
int h[N], e[M], w[M], ne[M], idx;
int dist[N], st[N], p[N], res[M];
vector<PII> query[N];
void add(int a, int b, int c) {
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
void dfs(int u, int fa) {
for (int i = h[u]; i != -1; i = ne[i]) {
int j = e[i];
if (j == fa) continue;
dist[j] = dist[u] + w[i];
dfs(j, u);
}
}
int find(int x) {
if (p[x] != x) p[x] = find(p[x]);
return p[x];
}
void tarjan(int u) {
st[u] = 1;
for (int i = h[u]; i != -1; i = ne[i]) {
int j = e[i];
if (!st[j]) {
tarjan(j);
p[j] = u;
}
}
for (auto it : query[u]) {
int y = it.ff, id = it.ss;
if (st[y] == 2) {
int anc = find(y);
res[id] = dist[u] + dist[y] - dist[anc] * 2;
}
}
st[u] = 2;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
memset(h, -1, sizeof h);
cin >> n >> m;
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;
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 << res[i] << endl;
return 0;
}