#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    ll to;
    ll weight;
    Edge(ll t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1000000000000001;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

vector<ll> dijkstra(ll s,ll n,Graph g){
    typedef pair<ll,ll> P;
    vector<ll> d(n,INF);
    priority_queue<P, vector<P>, greater<P>> que;
    d[s] = 0ll;
    que.push(P(0ll, s));
    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        if(d[v]<p.first) continue;
        for(ll i = 0; i<g[v].size(); i++){
            Edge e = g[v][i];
            if(d[e.to]>d[v]+e.weight){
                d[e.to] = d[v] + e.weight;
                que.push(P(d[e.to],e.to));
            }
        }
    }
    return d;
}

vector<int> get_path(int t,vector<int> prev){
    vector<int> path;
    for(; t != -1; t = prev[t]){
        path.emplace_back(t);
    }
    reverse(path.begin(),path.end());
    return path;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    Graph g(n);
    rep(i,n-1){
        ll a,b;
        ll c;
        cin >> a >> b >> c;
        a--;
        b--;
        g[a].emplace_back(Edge(b,c));
        g[b].emplace_back(Edge(a,c));
    }
    ll q,k;
    cin >> q >> k;
    k--;
    vector<ll> d = dijkstra(k,n,g);
    rep(i,q){
        ll x,y;
        cin >> x >> y;
        x--;
        y--;
        cout << d[x] + d[y] << endl;
    }
    Rep(i,n){
        debug(d[i]);
    }
}

Measured memory_bytes: 18160