import java.util.*

fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val nodes = Array(n) { mutableListOf<Pair<Int, Int>>() }

    repeat(n-1) {
        val (a, b, c) = readLine()!!.split(" ").map { it.toInt() }
        nodes[a-1].add(Pair(b-1, c))
        nodes[b-1].add(Pair(a-1, c))
    }

    val (q, k) = readLine()!!.split(" ").map { it.toInt() }
    val stack = Stack<Int>()
    val seen = BooleanArray(n)
    val distance = LongArray(n) { 0L }

    stack.push(k-1)

    while (stack.isNotEmpty()) {
        val idx = stack.pop()
        seen[idx] = true

        nodes[idx].forEach {
            if (seen[it.first]) return@forEach
            distance[it.first] = distance[idx] + it.second
            stack.push(it.first)
        }
    }

    repeat(q) {
        val (x, y) = readLine()!!.split(" ").map { it.toInt() }
        println(distance[x-1] + distance[y-1])
    }
}