import java.util.*

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)

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

// returns distance array
class ComparablePair(val first: Long, val second: Int) : Comparable<ComparablePair>  {
    override fun compareTo(other: ComparablePair): Int {
        return (this.first - other.first).toInt()
    }
}
fun dijkstra(graph: List<List<Edge>>, source: Int) : List<Long> {
    val queue = PriorityQueue<ComparablePair>()
    val d = LongArray(graph.size)

    d.fill(Long.MAX_VALUE);
    d[source] = 0
    queue.add(ComparablePair(0, source))

    while(!queue.isEmpty()) {
        val p = queue.poll()!!
        val v = p.second
        if (d[v] < p.first) {
            continue
        }

        // 最小距離が確定したノード周辺を調べる。
        for (i in 0 until graph[v].size) {
            val e = graph[v][i]
            if (d[e.to] > d[v] + e.distance) {
                d[e.to] = d[v] + e.distance
                queue.add(ComparablePair(d[e.to], e.to))
            }
        }
    }


    return d.toList()
}
