#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
vector< vector<int> > G(100002);
int n_v, n_e;
int prenum[100001], parent[100001], lowest[100001], n_child[100001];
bool is_cut[100001];


void dfs(int u, int f, int t_stamp){
    prenum[u] = t_stamp;
    parent[u] = f;
    lowest[u] = t_stamp;
    int v;
    for(int i=0; i<G[u].size(); i++){
        v = G[u][i];
        if(prenum[v]!=0){
            //this edge is a backedge
            lowest[u] = min(lowest[u], prenum[v]);
        }else{
            n_child[u] += 1;
            dfs(v, u, t_stamp+1);
            lowest[u] = min(lowest[u], lowest[v]);
        }
    }
    return;
}


int main(){
    
    scanf("%d %d", &n_v, &n_e);
    int u, v;
    for(int i=0; i<n_e; i++){
        scanf("%d %d", &u, &v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    memset(prenum, 0, sizeof(prenum));
    memset(parent, 255, sizeof(parent));
    memset(n_child, 0, sizeof(n_child));

    for(int i=0; i<n_v; i++){
        if(parent[i]==-1){
            dfs(i, -1, 1);
        }
    }

    memset(is_cut, 0, sizeof(is_cut));
    for(int i=0; i<n_v; i++){
        if(parent[i]==-1 && n_child[i]>=2)
            is_cut[i] = true;
        else if(prenum[parent[i]] <= lowest[i]){
            if(parent[parent[i]] == -1 && n_child[parent[i]]>=2){
                //the parent is a root
                is_cut[parent[i]] = true;
            }else if(parent[parent[i]] != -1){
                //the parent is not a root
                is_cut[parent[i]] = true;
            }
        }
    }
    
    for(int i=0; i<n_v; i++)
        if(is_cut[i])
            printf("%d\n", i);
    
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
#define MOD 1000000007
/*
void dijkstra(vector<vector<pair<ll,int>>> &graph, vll &dist, int s){
    priority_queue<pair<ll,int>> que;
    dist[s]=0;
    que.push({0,s});
    while(!que.empty()){
        auto x=que.top(); que.pop();
        if(dist[x.second]<x.first) continue;
        for(auto v:graph[x.second]){
            if(dist[v.second]<dist[x.second]+v.first) continue;
            dist[v.second]=dist[x.second]+v.first;
            que.push({dist[v.second],v.second});
        }
    } 
}
*/

void bfs(vector<vector<pair<ll,int>>> &graph, vll &dist, int s){
    queue<pair<ll,int>> que;
    dist[s]=0;
    que.push({0,s});
    while(!que.empty()){
        auto x=que.front(); que.pop();
        for(auto v:graph[x.second]){
            if(dist[v.second]!=-1) continue;
            dist[v.second]=dist[x.second]+v.first;
            que.push({dist[v.second],v.second});
        }       
    }
}

int main(){
    int n;
    cin >> n;
    vector<vector<pair<ll,int>>> graph(n);
    rep(i,n-1){
        int a,b;
        ll c;
        cin >> a >> b >> c;
        a--; b--;
        graph[a].push_back({c,b});
        graph[b].push_back({c,a});
    }    
    vll dist(n,-1);
    int q,k;
    cin >> q >> k; k--;
    //dijkstra(graph,dist,k);
    bfs(graph,dist,k);
    rep(i,q){
        int x,y;
        cin >> x >> y;
        x--; y--;
        cout << dist[x]+dist[y] << endl;
    }



}