#include <bits/stdc++.h>
using namespace std;

#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define TEN(n) ((ll)(1e##n))
#define fst first
#define snd second

string DBG_DLM(int &i){return(i++==0?"":", ");}
#define DBG_B(exp){int i=0;os<<"{";{exp;}os<<"}";return os;}
template<class T>ostream&operator<<(ostream&os,vector<T>v);
template<class T>ostream&operator<<(ostream&os,set<T>v);
template<class T>ostream&operator<<(ostream&os,queue<T>q);
template<class T>ostream&operator<<(ostream&os,priority_queue<T>q);
template<class T,class K>ostream&operator<<(ostream&os,pair<T,K>p);
template<class T,class K>ostream&operator<<(ostream&os,map<T,K>mp);
template<class T,class K>ostream&operator<<(ostream&os,unordered_map<T,K>mp);
template<int I,class TPL>void DBG(ostream&os,TPL t){}
template<int I,class TPL,class H,class...Ts>void DBG(ostream&os,TPL t){os<<(I==0?"":", ")<<get<I>(t);DBG<I+1,TPL,Ts...>(os,t);}
template<class T,class K>void DBG(ostream&os,pair<T,K>p,string delim){os<<"("<<p.first<<delim<<p.second<<")";}
template<class...Ts>ostream&operator<<(ostream&os,tuple<Ts...>t){os<<"(";DBG<0,tuple<Ts...>,Ts...>(os,t);os<<")";return os;}
template<class T,class K>ostream&operator<<(ostream&os,pair<T,K>p){DBG(os,p,", ");return os;}
template<class T>ostream&operator<<(ostream&os,vector<T>v){DBG_B(forr(t,v){os<<DBG_DLM(i)<<t;});}
template<class T>ostream&operator<<(ostream&os,set<T>s){DBG_B(forr(t,s){os<<DBG_DLM(i)<<t;});}
template<class T>ostream&operator<<(ostream&os,queue<T>q){DBG_B(for(;q.size();q.pop()){os<<DBG_DLM(i)<<q.front();});}
template<class T>ostream&operator<<(ostream&os,priority_queue<T>q){DBG_B(for(;q.size();q.pop()){os<<DBG_DLM(i)<<q.top();});}
template<class T,class K>ostream&operator<<(ostream&os,map<T,K>m){DBG_B(forr(p,m){os<<DBG_DLM(i);DBG(os,p,"->");});}
template<class T,class K>ostream&operator<<(ostream&os,unordered_map<T,K>m){DBG_B(forr(p,m){os<<DBG_DLM(i);DBG(os,p,"->");});}
#define DBG_OVERLOAD(_1,_2,_3,_4,_5,_6,macro_name,...)macro_name
#define DBG_LINE(){char s[99];sprintf(s,"line:%3d | ",__LINE__);cerr<<s;}
#define DBG_OUTPUT(v){cerr<<(#v)<<"="<<(v);}
#define DBG1(v,...){DBG_OUTPUT(v);}
#define DBG2(v,...){DBG_OUTPUT(v);cerr<<", ";DBG1(__VA_ARGS__);}
#define DBG3(v,...){DBG_OUTPUT(v);cerr<<", ";DBG2(__VA_ARGS__);}
#define DBG4(v,...){DBG_OUTPUT(v);cerr<<", ";DBG3(__VA_ARGS__);}
#define DBG5(v,...){DBG_OUTPUT(v);cerr<<", ";DBG4(__VA_ARGS__);}
#define DBG6(v,...){DBG_OUTPUT(v);cerr<<", ";DBG5(__VA_ARGS__);}
#define DEBUG0(){DBG_LINE();cerr<<endl;}
#ifdef LOCAL
#define out(...){DBG_LINE();DBG_OVERLOAD(__VA_ARGS__,DBG6,DBG5,DBG4,DBG3,DBG2,DBG1)(__VA_ARGS__);cerr<<endl;}
#else
#define out(...)
#endif

using ll=long long;
using pii=pair<int,int>;using pll=pair<ll,ll>;using pil=pair<int,ll>;using pli=pair<ll,int>;
using vs=vector<string>;using vvs=vector<vs>;using vvvs=vector<vvs>;
using vb=vector<bool>;using vvb=vector<vb>;using vvvb=vector<vvb>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template<class A,class B>bool amax(A&a,const B&b){return b>a?a=b,1:0;}
template<class A,class B>bool amin(A&a,const B&b){return b<a?a=b,1:0;}
ll ri(){ll l;cin>>l;return l;} string rs(){string s;cin>>s;return s;}


using Weight = int;
struct Edge {
  int dst;
  Weight weight;
  Edge() : dst(0), weight(0) {}
  Edge(int d, Weight w = 1) : dst(d), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;


template <class T> struct SparseTable {
  vector<vector<T>> table;

  SparseTable() {}
  SparseTable(const vector<T> &A) {
    init(A);
  }

  void init(const vector<T> &A) {
    int n = (int) A.size();
    int height = 32 - __builtin_clz(n - 1);
    int width = 1 << height;
    table.resize(height, vector<T>(width));
    for (int i = 0; i < width; i++) table[0][i] = A[i];
    for (int i = 1; i < height; i++) for (int j = 0; j < width; j++) {
      const int b = ((j >> i) | 1) << i;
      table[i][j] = (j >> i) & 1 ? query(b, j) : query(j, b-1);
    }
  }

  T query(int l, int r) {
    if (l == r) return table[0][l];
    const int d = 31 - __builtin_clz(l ^ r);
    return min(table[d][l], table[d][r]);
  }
};
template <class RMQ> struct _LCA {
  size_t n;
  vector<int> D, P, L, R;
  vector<pair<int, int>> ET;
  vector<long long> WD;
  RMQ rmq;

  _LCA(const Graph &G, int root = 0) : n(G.size()), D(n), P(n), L(n), R(n), WD(n) {
    dfs(G, root);
    rmq.init(ET);
  }

  void dfs(const Graph &G, int root = 0) {
    vector<int> count(n);
    stack<int> S; S.push(root);
    while (!S.empty()) {
      int v = S.top(); S.pop();
      if (count[v] == 1) {
        count[v] = 2;
        R[v] = ET.size() - 1;
        if (P[v] >= 0) ET.emplace_back(D[P[v]], P[v]);
      }
      else if (count[v] == 0) {
        S.push(v);
        count[v] = 1;
        L[v] = ET.size();
        ET.emplace_back(D[v], v);
        for (auto &edg : G[v]) if (!count[edg.dst]) {
          D[edg.dst] = D[v] + 1;
          WD[edg.dst] = WD[v] +  edg.weight;
          P[edg.dst] = v;
          S.push(edg.dst);
        }
      }
    }
  }

  int query(int u, int v) {
    u = L[u]; v = L[v];
    if (u > v) swap(u, v);
    return rmq.query(u, v).second;
  }

  long long dist(int u, int v) {
    return WD[u] + WD[v] - 2 * WD[query(u, v)];
  }
};
using LCA = _LCA<SparseTable<pair<int, int>>>;

void Main() {
  int n = ri();
  Graph G(n);
  rep(i, n-1) {
    int u = ri() - 1;
    int v = ri() - 1;
    int64_t w = ri();
    G[u].emplace_back(v, w);
    G[v].emplace_back(u, w);
  }

  int q = ri();
  int k = ri() - 1;

  LCA lca(G, k);


  while (q--) {
    int u = ri()-1;
    int v = ri()-1;

    int l = lca.query(u, v);

    ll dist = lca.dist(u, v);
    if (l == k) {
      cout << dist << endl;
    }
    else {
      ll d2 = lca.dist(l, k);
      cout << (dist + d2 * 2) << endl;
    }
  }
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  Main();
  return 0;
}

Measured memory_bytes: 50156