#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
#define MAX 10000 + 10
#define inf 0x3f3f3f3f3f
long long dis[MAX];
bool vis[MAX];
long long map[MAX][MAX];
void Spfa(int start,int n){
	for (int i = 0; i <= n; ++i)
		dis[i] = inf, vis[i] = false;
	queue<int> Q; Q.push(start);
	dis[start] = 0;
	vis[start] = true;
	while (!Q.empty()){
		int u = Q.front(); Q.pop();
		for (int i = 1; i <= n; ++i){
			if(dis[i] > dis[u] + map[u][i]){
				dis[i] = dis[u] + map[u][i];
				if (!vis[i])
					Q.push(i), vis[i] = true;    
			}
		}
		vis[u] = false;            
	}   
}

int main(void){
	int n;
	while(~scanf("%d",&n)){
		int x,y;
		long long vla;
		memset(map, inf, sizeof(map));
		for(int i = 0; i < n - 1;i++){
			scanf("%d %d %lld", &x, &y, &vla);
			if(vla < map[x][y]) map[x][y] = map[y][x] = vla;
		}
		int m, key;
		scanf("%d %d", &m, &key);
		int start, end;
		for(int i = 0; i < m; i++){
			long long ans = 0;
			scanf("%d %d", &start, &end);
			if(key < start) Spfa(key,start), ans += dis[start];
			else Spfa(start,key), ans += dis[key];
			
			//printf("%lld\n",dis[key]);
			if(key > end) Spfa(end,key), ans += dis[key];
			else Spfa(key,end), ans += dis[end];

			//printf("%lld\n",dis[end]);
			printf("%lld\n",ans);

		}
	}
	return 0;
}

		