#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n;
struct edge{/*重み付き,有向*/
    int to , cost;/*toは接続先*/
    edge(ll to_ ,ll cost_ = 1){ to=to_; cost=cost_; };/*全てのcost=1 <=> 無向グラフ*/
};
bool operator<(edge e1 ,edge e2){return e1.cost < e2.cost; }
bool operator>(edge e1 ,edge e2){return e1.cost > e2.cost; }
using graph =  vector< vector<edge> >;
graph g,g2;
ll q,k;
Vi x,y;
Vi dist; //for dijkstra. distance from start
void dijkstra(ll start){
    dist.resize(g.size()); dist.resize(g.size());
    rep(i,dist.size())dist[i]=INF;
    auto comp_pq = [](pair<ll,ll> x,pair<ll,ll> y){return x.second > y.second;};
    priority_queue< pair<ll,ll> , vector<pair<ll,ll>>, decltype(comp_pq)> pq{comp_pq};
    dist[start]=0; pq.push(mp(start,0));
    while (pq.size()>0){
        PLL p = pq.top();
        pq.pop();
        if(p.second > dist[p.first])continue;
        rep(i,g[p.first].size()){
            if(dist[p.first]!=INF){
                if(chmin(dist[g[p.first][i].to],dist[p.first]+g[p.first][i].cost)){
                    pq.push(mp(g[p.first][i].to,dist[g[p.first][i].to]));
                }
            }
        }
    }
}
Vi dist2; //for dijkstra. distance from start
void dijkstra2(ll start){
    dist2.resize(g2.size()); dist2.resize(g2.size());
    rep(i,dist2.size())dist2[i]=INF;
    auto comp_pq = [](pair<ll,ll> x,pair<ll,ll> y){return x.second > y.second;};
    priority_queue< pair<ll,ll> , vector<pair<ll,ll>>, decltype(comp_pq)> pq{comp_pq};
    dist2[start]=0; pq.push(mp(start,0));
    while (pq.size()>0){
        PLL p = pq.top();
        pq.pop();
        if(p.second > dist2[p.first])continue;
        rep(i,g2[p.first].size()){
            if(dist2[p.first]!=INF){
                if(chmin(dist2[g2[p.first][i].to],dist2[p.first]+g2[p.first][i].cost)){
                    pq.push(mp(g2[p.first][i].to,dist2[g2[p.first][i].to]));
                }
            }
        }
    }
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n;
    g.resize(n+1);g2.resize(n+1);
    ll in,inp,inpp;
    rep(i,n-1){
        cin>>in>>inp>>inpp;
        g[in].pb(edge(inp,inpp));
        g[inp].pb(edge(in,inpp));
        g2[inp].pb(edge(in,inpp));
    }
    cin>>q>>k;
    dijkstra(k);
    x.resize(q); y.resize(q);
    rep(i,q){
        cin>>x[i]>>y[i];
        print(dist[x[i]]+dist[y[i]]);
    }

    return 0;
}

Measured memory_bytes: 15444