import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.container;
import std.array;
import std.math;
import std.range;
import std.typecons;
import std.ascii;
import std.format;

class Iku {
  int dist;
  long cost;
}

class Node {
  int now;
  long cost;
}

void bfs(int k, int n, Iku[][] adj, long[] memo)
{
  Node[] queue;
  Node atom = new Node();
  atom.now = k;
  atom.cost = 0;
  queue ~= atom;
  bool[] done = new bool[n + 1];
  while (queue.length) {
    Node node = queue.front;
    queue = queue[1..$];
    if (done[node.now]) {
      continue;
    }
    done[node.now] = true;
    memo[node.now] = node.cost;
    foreach (Iku iku; adj[node.now]) {
      Node next = new Node();
      next.cost = node.cost + iku.cost;
      next.now = iku.dist;
      queue ~= next;
    }
  }
}

void main()
{
  int n = readln.chomp.to!int;
  Iku[][] adj = new Iku[][](n + 1, 0);
  foreach (i; 0..n - 1) {
    auto l = readln.chomp.split.map!(to!int).array;
    Iku left = new Iku();
    left.dist = l[1];
    left.cost = l[2];
    adj[l[0]] ~= left;
    Iku right = new Iku();
    right.dist = l[0];
    right.cost = l[2];
    adj[l[1]] ~= right;
  }
  long[] memo = new long[n + 1];
  memo[] = -1;
  auto l = readln.chomp.split.map!(to!int).array;
  int q = l[0];
  int k = l[1];
  bfs(k, n, adj, memo);
  foreach (i; 0..q) {
    auto m = readln.chomp.split.map!(to!int).array;
    int x = m[0];
    int y = m[1];
    long sum = memo[x] + memo[y];
    writeln = sum;
  }
}
