import java.util.ArrayDeque

fun main(args: Array<String>) {
    val N = readInputLine().toInt()

    val edges = Array(100000) { mutableListOf<Pair<Int, Long>>() }

    for (i in 1 until N) {
        val (a, b, c) = readInputLine().split(" ").map { it.toInt() }
        edges[a - 1].add(Pair(b - 1, c.toLong()))
        edges[b - 1].add(Pair(a - 1, c.toLong()))
    }
    
    val (Q, K) = readInputLine().split(" ").map { it.toInt() - 1 }

    val dist = LongArray(100000) { Long.MAX_VALUE }
    
    val queue = ArrayDeque<Int>()
    queue.add(K)
    dist[K] = 0L
    
    while (!queue.isEmpty()) {
        val now = queue.poll()!!
        
        for ((k, v) in edges[now]) {
            if (dist[k] == Long.MAX_VALUE) {
                dist[k] = dist[now] + v
                queue.add(k)
            }
        }
    }

    for (i in 0..Q) {
        val (x, y) = readInputLine().split(" ").map { it.toInt() - 1 }
        println(dist[x] + dist[y])
    }
}

fun readInputLine(): String {
    return readLine()!!
}
