fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val g = Graph(n,n-1)
    val (q,k) = readLine()!!.split(" ").map { it.toInt() }
    val qs = (1..q).map { readLine()!!.split(" ").map { it.toInt() } }

    val d = g.makeRootedTree(k)
    qs.map {
        d[it[0]] + d[it[1]]
    }.joinToString("\n").let { println(it) }
}

class Graph (val N: Int, val M: Int){

    data class Edge(val to: Int, val cost: Long)

    val adj = run {
        val adjList = Array<MutableList<Edge>>(N+1){ mutableListOf()}
        (1..M).forEach {
            val line = readLine()!!.split(" ")
            val from = line[0].toInt()
            val to = line[1].toInt()
            val cost = line.getOrElse(2){"1"}.toLong()
            adjList[from].add(Edge(to,cost))
            adjList[to].add(Edge(from,cost))
        }
        adjList.map { it.toList() }
    }

    // root を根とした根付き木を返す。
    fun makeRootedTree(root: Int): LongArray{
        val parent = IntArray(N+1){-1}
        val dist = LongArray(N+1){-1}
        dist[root] = 0L
        dfs(root, parent, dist)
        return dist
    }

    fun dfs(v: Int, parent: IntArray, dist: LongArray) {
        adj[v].filter { dist[it.to]==-1L }.forEach {
            parent[it.to] = v
            dist[it.to] = dist[v] + it.cost
            dfs(it.to, parent, dist)
        }
    }
}
