data class Edge(val to: Int, val distance: Long)
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()

    val graph = Array(N, { mutableListOf<Edge>()}).toList() // contains edge index

    for (i in 0 until N - 1) {
        val (a, b, c) = readLine()!!.split(" ").map { it.toInt() }
        val from = a - 1
        val to = b - 1
        graph[from].add(Edge(to, c.toLong()))
        graph[to].add(Edge(from, c.toLong()))
    }
    val (Q, K) = readLine()!!.split(" ").map { it.toInt() }

    // Compute distance from K for each node
    // Kを単一始点として、最短距離を求める。
    // O (ElogV) = (ELogE)
    //val distanceFromK = dijkstra(graph, K - 1)

    // DFS O(2N)
    val d = LongArray(N)
    val defaultValue = Long.MAX_VALUE
    d.fill(defaultValue);
    d[K-1] = 0
    fun dfs(current: Int) {
        graph[current].forEach { edge ->
            if (d[edge.to] == defaultValue) {
                d[edge.to] = d[current] + edge.distance
                dfs(edge.to)
            }
        }
    }
    dfs(K-1)

    // Process queries O(Q)
    for (i in 0 until Q) {
        val (x, y) = readLine()!!.split(" ").map { it.toInt() }
        val xk = d[x - 1]
        val ky = d[y - 1]
        println(xk + ky)
    }
}