import java.util.concurrent.LinkedBlockingQueue

fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main() {
    data class Edge(val from: Long, val to: Long, val distance: Long)

    val n = readLine()?.toInt() ?: return
    val edges = hashMapOf<Long, MutableList<Edge>>()
    repeat(n - 1) {
        val (a, b, c) = longList()
        edges.getOrPut(a) { mutableListOf() }.add(Edge(a, b, c))
        edges.getOrPut(b) { mutableListOf() }.add(Edge(b, a, c))
    }
    val (q, k) = intList()
    val arrived = Array(n + 1) { false }
    val distances = Array(n + 1) { 0L }
    val queue = LinkedBlockingQueue<Pair<Long, Long>>()
    queue.add(Pair(k.toLong(), 0L))
    arrived[k] = true
    while (queue.isNotEmpty()) {
        val (v, d) = queue.poll()
        edges[v]?.forEach {
            val to = it.to.toInt()
            if (!arrived[to]) {
                arrived[to] = true
                val distance = d + it.distance
                distances[to] = distance
                queue.add(Pair(it.to, distance))
            }
        }
    }
    buildString {
        repeat(q) {
            val (x, y) = intList()
            appendln(distances[x] + distances[y])
        }
    }.let {
        println(it.trimIndent())
    }
}
