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;
}

alias His = Tuple!(int, "now", int, "from", long, "cost");

long search(int x, int k, int n, Iku[][] adj, long[] memo)
{
  RedBlackTree!(His, (a, b) => a.cost < b.cost) queue;
  queue = new typeof(queue);
  His atom = His(x, -1, 0);
  queue.insert = atom;
  His[] hist = new His[](n + 1);
  hist[] = His(-1, -1, -1);
  while (queue.length) {
    His node = queue.front;
    queue.removeFront;
    if (hist[node.now].now != -1) {
      continue;
    }
    hist[node.now] = node;
    if (memo[node.now] != -1) {
      long cost = node.cost;
      int ite = node.from;
      while (ite != -1) {
        memo[ite] = cost - hist[ite].cost + memo[node.now];
        ite = hist[ite].from;
      }
      break;
    }
    if (node.now == k) {
      long cost = node.cost;
      int ite = node.from;
      while (ite != -1) {
        memo[ite] = cost - hist[ite].cost;
        ite = hist[ite].from;
      }
      break;
    }
    foreach (Iku iku; adj[node.now]) {
      His next = His(iku.dist, node.now, node.cost + iku.cost);
      queue.insert = next;
    }
  }
  return memo[x];
}

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];
  foreach (i; 0..q) {
    auto m = readln.chomp.split.map!(to!int).array;
    int x = m[0];
    int y = m[1];
    long sum = search(x, k, n, adj, memo) + search(y, k, n, adj, memo);
    writeln = sum;
  }
}
