#include "bits/stdc++.h"

using namespace std;

void Main() {
    long long N;
    cin >> N;
    map<long long, set<pair<long long, long long> > > tree;
    for (long long i = 0; i < N - 1; ++i) {
        long long a, b, c;
        cin >> a >> b >> c;
        if (tree.count(a) == 0) {
            tree.insert(make_pair(a, set<pair<long long, long long> >()));
        }
        tree[a].insert(make_pair(b, c));
        if (tree.count(b) == 0) {
            tree.insert(make_pair(b, set<pair<long long, long long> >()));
        }
        tree[b].insert(make_pair(a, c));
    }

    long long Q, K;
    cin >> Q >> K;
    vector<long long> distanceFromK(N + 1, -1LL);
    distanceFromK[K] = 0LL;
    queue<long long> q;
    q.push(K);
    while (!q.empty()) {
        long long f = q.front();
        q.pop();
        long long distanceFromTop = distanceFromK[f];
        const set<pair<long long, long long> >& nextNodes = tree[f];
        for (auto e : nextNodes) {
            if (distanceFromK[e.first] < 0) {
                q.push(e.first);
                distanceFromK[e.first] = e.second + distanceFromTop;
            }
        }
    }

    for (long long i = 0; i < Q; ++i) {
        long long x, y;
        cin >> x >> y;
        long long dx = distanceFromK[x];
        long long dy = distanceFromK[y];
        cout << (dx + dy) << endl;
    }

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll INF = 1LL << 60;

ll N, Q;
vector<tuple<ll, ll, ll>> v;
set<P> st;

int main() {
    cin >> N >> Q;
    v.resize(N);

    rep(i, N) {
        ll s, t, x;
        cin >> s >> t >> x;
        v[i] = make_tuple(x, s, t);
    }
    sort(v.begin(), v.end());

    rep(i, Q) {
        ll d; cin >> d;
        st.insert(P(d, i));        
    }

    vector<ll> ans(Q);

    rep(i, N) {
        ll x, l, r;
        tie(x, l, r) = v[i];

        auto iter = st.lower_bound(P(l - x, -1));
        while (iter != st.end()) {
            if (iter->first >= r - x) break; 
            ans[iter->second] = x;
            st.erase(iter++);
        }
    }

    rep(i, Q) {
        if (ans[i] == 0) {
            cout << -1 << endl;
        } else {
            cout << ans[i] << endl;
        }
    }
}