#include <iostream>
#include <queue>
#include <cmath>
using namespace std;
const int N = 1e5 + 10, M = 2 * N;
int h[N], e[M], ne[M], w[M], idx;
int T, n, m, t;
void add(int a, int b, int c)
{
e[++idx] = b;
ne[idx] = h[a];
h[a] = idx;
}
int f[N][20], d[N], dist[N];
queue<int> q;
void bfs()
{
q.push(1);
d[1] = 1;
while (q.size())
{
int x = q.front();
q.pop();
for (int i = h[x]; i != -1; i = ne[i])
{
int y = e[i];
if (d[y])
continue;
d[y] = d[x] + 1;
dist[y] = dist[x] + w[i];
f[y][0] = x;
for (int j = 1; j <= t; j++)
f[y][j] = f[f[y][j - 1]][j - 1];
q.push(y);
}
}
}
void dfs(int u, int father, int ver)
{
f[u][0] = father;
dist[u] = dist[father] + ver;
d[u] = d[father] + 1;
for (int i = 1; i <= t; i++)
f[u][i] = f[f[u][i - 1]][i - 1];
for (int i = u; i != -1; i = ne[i])
{
int j = e[i];
if (j != father)
dfs(j, u, w[i]);
}
}
long long lca(int x, int y)
{
if (d[x] > d[y])
swap(x, y);
for (int i = t; i >= 0; i--)
{
if (d[f[y][i]] >= d[x])
y = f[y][i];
}
if (x == y)
return x;
for (int i = t; i >= 0; i--)
if (f[x][i] != f[y][i])
x = f[x][i], y = f[y][i];
return f[x][0];
}
int main()
{
ios::sync_with_stdio(false);
cin >> T;
while (T--)
{
cin >> n >> m;
t = (int) (log(n) / log(2)) + 1;
for (int i = 1; i <= n; i++)
h[i] = d[i] = 0;
idx = 0;
for (int i = 1; i < n; i++)
{
int x, y, z;
cin >> x >> y >> z;
add(x, y, z);
add(y, x, z);
}
bfs();
for (int i = 1; i <= m; i++)
{
int x, y;
cin >> x >> y;
printf("%d\n", dist[x] + dist[y] - 2 * dist[lca(x, y)]);
}
}
return 0;
}