import java.io.*
import java.util.*

var pw = PrintWriter(System.out)
fun solve(N: Int, a: IntArray, b: IntArray, c: LongArray, Q: Int, K: Int, x: IntArray, y: IntArray){
    val tree = AdjacentListGraph<Int, Long>(Array(N){ Vertex<Int, Long>() }.toMutableList())
    for(i in 0 until N - 1){
        tree.addEdge(a[i] - 1, b[i] - 1, c[i])
        tree.addEdge(b[i] - 1, a[i] - 1, c[i])
    }
    val distances = tree.getDistances(K - 1)
    // println(distances.toList())
    repeat(Q){
        val ans = distances[x[it] - 1] + distances[y[it] - 1]
        pw.println(ans)
    }
    pw.flush()
    return
}

// fun AdjacentListGraph<Int, Long>.getDistances(from: Int): LongArray{
//     // Depath First Search
//     val distances = LongArray(vertices.size){ -1L }

//     fun dfs(node: Int, dist: Long){
//         if (distances[node] != -1L) return
//         distances[node] = dist
//         vertices[node].edges.forEach{ dfs(it.to, dist + it.weight!!) }
//     }
//     dfs(from, 0)
//     return distances
// }

fun AdjacentListGraph<Int, Long>.getDistances(from: Int): LongArray{
    // Breadth First Search
    val distances = LongArray(vertices.size){ -1L }
    distances[from] = 0
    val queue = ArrayDeque<Int>()
    queue.add(from)
    while(queue.size > 0){
        val node = queue.removeFirst()
        val curDist = distances[node]
        vertices[node].edges.filter{ distances[it.to] == -1L }.forEach{
            val delta = it.weight?: 1L
            distances[it.to] = curDist + delta
            queue.add(it.to)
        }
    }
    return distances
}

data class Vertex<T : Comparable<T>, E : Comparable<E>>(val data: T? = null) {
    data class Edge<T : Comparable<T>>(val to: Int, val weight: T? = null)

    val edges = mutableListOf<Edge<E>>()

    fun addEdge(to: Int, weight: E?) = edges.add(Edge(to, weight))

    fun removeEdge(to: Int): Boolean{
        for ((i, edge) in edges.withIndex()){
            if (edge.to == to){
                edges.removeAt(i)
                return true
            }
        }
        return false
    }
}

class AdjacentListGraph<T : Comparable<T>, E : Comparable<E>>(
    val vertices: MutableList<Vertex<T, E>>
) {
    // T = data of Vertex, E = weight of Edge
    fun getWeight(from: Int, to: Int): E? = vertices[from].edges.find { it.to == to }?.weight
    fun addEdge(from: Int, to: Int, weight: E? = null) = vertices[from].addEdge(to, weight)
    fun removeEdge(from: Int, to: Int) = vertices[from].removeEdge(to)
    fun isAdjacent(from: Int, to: Int) = vertices[from].edges.find { it.to == to } != null
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val a = IntArray(N-1)
    val b = IntArray(N-1)
    val c = LongArray(N-1)
    for (i in 0 until N-1) {
        a[i] = sc.next().toInt()
        b[i] = sc.next().toInt()
        c[i] = sc.next().toLong()
    }
    val Q = sc.next().toInt()
    val K = sc.next().toInt()
    val x = IntArray(Q.toInt())
    val y = IntArray(Q.toInt())
    for (i in 0 until Q.toInt()) {
        x[i] = sc.next().toInt()
        y[i] = sc.next().toInt()
    }
    solve(N, a, b, c, Q, K, x, y)
}



Measured memory_bytes: 101136