#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define all(x) (x).begin(), (x).end()
#define MASK(i) (1LL<<(i))
#define BIT(i,n) (((n)>>(i)) & 1LL)
#define MIN_HIGH(x, y) (h[x] < h[y] ? (x) : (y));

template <class X, class Y>
    bool minimize(X& x, const Y& y)
    {
        if(x > y){
            x = y;
            return 1;
        }
        return 0;
    }

template <class X, class Y>
    bool maximize(X& x, const Y& y)
    {
        if(x < y){
            x = y;
            return 1;
        }
        return 0;
    }

const int N = 1e3 + 5;
const int LOG = 10;

int n, q, nodes[N << 1], d[N], pos[N], h[N], cnt = 0, minH[LOG + 2][N << 1];
vector<pair<int, int>> adj[N];

void dfs(int x, int p)
{
    nodes[++cnt] = x;
    pos[x] = cnt;
    for(const auto& y : adj[x]) if(y.fi != p) {
        d[y.fi] = d[x] + y.se;
        h[y.fi] = h[x] + 1;
        dfs(y.fi, x);
        nodes[++cnt] = x;
    }
}

int lca(int x, int y)
{
    int px = pos[x], py = pos[y];
    if(px > py) swap(px, py);

    int k = 31 - __builtin_clz(py - px + 1);
    return MIN_HIGH(minH[k][px], minH[k][py - MASK(k) + 1]);
}

void process()
{
    cin >> n >> q;
    for(int i = 1; i < n; ++i){
        int u, v, w; cin >> u >> v >> w;
        adj[u].push_back({v, w});
        adj[v].push_back({u, w});
    }

    dfs(1, -1);

    for(int i = 1; i <= cnt; ++i)
        minH[0][i] = nodes[i];
    for(int j = 1; j <= LOG; ++j)
        for(int i = 1; i + MASK(j) - 1 <= cnt; ++i)
            minH[j][i] = MIN_HIGH(minH[j - 1][i], minH[j - 1][i + MASK(j - 1)]);

    while(q--){
        int x, y; cin >> x >> y;
        cout << d[x] + d[y] - 2 * d[lca(x, y)] << "\n";
    }
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    #define file "thieufilethinguhetcuu"
    if(fopen(file".inp","r")){
        freopen(file".inp","r",stdin);
        freopen(file".out","w",stdout);
    }
    int _ = 1;
//    cin >> _;
    while(_--){
        process();
    }
    return 0;
}
