You are given a tree with N vertices.
Here, a tree is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices.
The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i.

You are also given Q queries and an integer K. In the j-th query (1≤j≤Q):

* find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.

Constraints

* 3≤N≤10^5
* 1≤a_i,b_i≤N (1≤i≤N-1)
* 1≤c_i≤10^9 (1≤i≤N-1)
* The given graph is a tree.
* 1≤Q≤10^5
* 1≤K≤N
* 1≤x_j,y_j≤N (1≤j≤Q)
* x_j≠y_j (1≤j≤Q)
* x_j≠K,y_j≠K (1≤j≤Q)

Input

Input is given from Standard Input in the following format:


N
a_1 b_1 c_1
:
a_{N-1} b_{N-1} c_{N-1}
Q K
x_1 y_1
:
x_{Q} y_{Q}


Output

Print the responses to the queries in Q lines.
In the j-th line j(1≤j≤Q), print the response to the j-th query.

Examples

Input

5
1 2 1
1 3 1
2 4 1
3 5 1
3 1
2 4
2 3
4 5


Output

3
2
4


Input

7
1 2 1
1 3 3
1 4 5
1 5 7
1 6 9
1 7 11
3 2
1 3
4 5
6 7


Output

5
14
22


Input

10
1 2 1000000000
2 3 1000000000
3 4 1000000000
4 5 1000000000
5 6 1000000000
6 7 1000000000
7 8 1000000000
8 9 1000000000
9 10 1000000000
1 1
9 10


Output

17000000000
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	final long MODULO = 1_000_000_000 + 7;

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n - 1];
		int[] b = new int[n - 1];
		int[] c = new int[n - 1];
		HLDecomposition hl = new HLDecomposition(n);
		for (int i = 0; i < n - 1; ++i) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
			--a[i];
			--b[i];
			hl.ae(a[i], b[i], c[i]);
		}
		int Q = sc.nextInt();
		int K = sc.nextInt();
		--K;
		int[] x = new int[Q];
		int[] y = new int[Q];
		hl.root = K;
		hl.pre();
		for (int i = 0; i < Q; ++i) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			--x[i];
			--y[i];
			System.out.println(hl.depth2[x[i]] + hl.depth2[y[i]]);
		}
	}

	class HLDecomposition {
		int root = 0;
		int n;
		int[] depth;
		long[] depth2;
		int[] head;
		int[] heavy;
		int[] parent;
		int[] sz;
		ArrayList<Edge>[] g;
		int[] id;

		class Edge {
			int src, dst;
			long cost;

			public Edge(int src_, int dst_, int cost_) {
				src = src_;
				dst = dst_;
				cost = cost_;
			}
		}

		@SuppressWarnings("unchecked")
		public HLDecomposition(int n) {
			this.n = n;
			depth = new int[n];
			depth2 = new long[n];
			head = new int[n];
			heavy = new int[n];
			parent = new int[n];
			id = new int[n];
			sz = new int[n];
			g = new ArrayList[n];
			for (int i = 0; i < n; ++i) {
				g[i] = new ArrayList<>();
			}
			Arrays.fill(head, -1);
			Arrays.fill(id, -1);
			Arrays.fill(parent, -1);
		}

		void ae(int a, int b, int c) {
			g[a].add(new Edge(a, b, c));
			g[b].add(new Edge(b, a, c));
		}

		void pre() {
			dfs(root, -1);
			bfs();
		}

		void bfs() {
			ArrayDeque<Integer> pend = new ArrayDeque<>();
			int gen = 0;
			pend.add(0);
			while (!pend.isEmpty()) {
				int v = pend.pollFirst();
				int top = v;
				for (; v != -1; v = heavy[v]) {
					id[v] = gen++;
					head[v] = top;
					for (Edge e : g[v]) {
						int d = e.dst;
						if (d == parent[v] || d == heavy[v]) {
							continue;
						}
						pend.add(d);
					}
				}
			}
		}

		int lca(int u, int v) {
			if (head[u] != head[v]) {
				if (depth[head[u]] < depth[head[v]]) {
					int tmp = u;
					u = v;
					v = tmp;
				}
				return lca(parent[head[u]], v);
			} else {
				if (depth[u] > depth[v]) {
					int tmp = u;
					u = v;
					v = tmp;
				}
				return u;
			}
		}

		int dfs(int c, int p) {
			parent[c] = p;
			int s = 1;
			int to = -1;
			for (Edge e : g[c]) {
				int d = e.dst;
				if (d == p)
					continue;
				depth[d] = depth[c] + 1;
				depth2[d] = depth2[c] + e.cost;
				s += dfs(d, c);
				if (to == -1 || sz[d] > sz[to]) {
					to = d;
				}
			}
			sz[c] = s;
			heavy[c] = to;
			return s;
		}

	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}
