#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

#define maxn 10000+10

long long dis[maxn][maxn];
int n;

int main()
{
	while (scanf("%d", &n)!=EOF)
	{
		memset(dis, maxn, sizeof(dis));
		for (int i = 0;i < n-1;i++)
		{
			int x, y, d;
			scanf("%d%d%d", &x, &y, &d);
			dis[x][y] = dis[y][x] = d;
		}
		for (int k = 1; k <= n; k++) {  
			for (int i = 1; i <= n; i++) {  
				for (int j = 1; j <= n; j++) {  
					dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);  
				}  
			}
		}
		int a, b;
		scanf("%d%d", &a, &b);
		while(a--)
		{
			int x, y;
			scanf("%d%d", &x, &y);
			long long temp = dis[x][b] + dis[b][y];
			printf("%lld\n", temp);
		}
	}return 0;
}