//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
//using Graph = vector<vector<int>>;
typedef long long ll;
using Graph = vector<vector<pair<ll,ll>>>;
const int mod =1e+9+7;

const int dy[4]={0,1,0,-1};
const int dx[4]={1,0,-1,0};
const ll INF=1e10;

int main(){
    ll n; cin>>n;
    Graph G(n);
    rep(i,n-1){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        G[a].push_back(make_pair(b,c));
        G[b].push_back(make_pair(a,c));
    }
    ll q,k; cin>>q>>k;
    k--;
 
    vector<ll>dist(n,0);
    queue<ll>que;
    vector<bool>seen(n,false);
    que.push(k);
    while(!que.empty()){
        ll v=que.front();que.pop();
        seen[v]=true;
        for(auto nv:G[v]){
            if(seen[nv.first]==true)continue;
            dist[nv.first]=dist[v]+nv.second;
            que.push(nv.first);
        }
    }
    vector<ll>x(q),y(q);
    rep(i,q){
        cin>>x[i]>>y[i];
        x[i]--;y[i]--;
    }
    rep(i,q){
        cout<<dist[x[i]]+dist[y[i]]<<endl;
    }


    /*rep(i,n){
        cout<<dist[i]<<" ";
    }
    cout<<endl;*/

}










#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int distance[10], v1, v2;
    char garbage;
    while(cin >> distance[0]){
        cin >> garbage;
        double lineLength = distance[0];
        range(i,1,10){
            cin >> distance[i] >> garbage;
            lineLength+= distance[i];
        }
        cin >> v1 >> garbage >> v2;
        double sum_v = v1 + v2;
        double time = lineLength / sum_v;
        double pass_location = v1 * time;
        rep(i,10){
            pass_location-= static_cast<double>(distance[i]);
            if(pass_location <= 0){
                cout << i + 1 << endl;
                break;
            }
        }
    }
}