fun main(arg: Array<String>) {
    val INF = 1L.shl(40)
    val N = nextInt()
    val G = Array(N) { mutableListOf<Pair<Int, Long>>() }
    repeat(N - 1) {
        val (a, b, c) = listOfInt(-1, -1, 0)
        val C = c.toLong()
        G[a].add(b to C); G[b].add(a to C)
    }
    val R = LongArray(N)
    fun dfs(v: Int, p: Int) {
        for ((u, c) in G[v]) {
            if (u == p) continue
            R[u] += R[v] + c
            dfs(u, v)
        }
    }
    val (Q, K) = listOfInt(0, -1)
    dfs(K, -1)
    val ans = LongArray(Q)
    repeat(Q) { q ->
        val (x, y) = listOfInt(-1, -1)
        ans[q] = R[x] + R[y]
    }
    println(ans.joinToString("\n"))
}
fun gcd(a: Long, b: Long): Long = if (b > 0) gcd(b, a % b) else a
fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")

fun listOfInt(vararg deltas: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + deltas[index % deltas.size] }

