using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace AtCoder.D
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var dists = Enumerable.Range(0, (int)N)
                .ToDictionary(x => x, y => new List<Path>());
            for (var i = 0; i < N - 1; i++)
            {
                var (a, b, c) = Read3Longs();
                a--; b--; // インデックス変換

                dists[(int)a].Add(new Path { From = a, To = b, Dist = c });
                dists[(int)b].Add(new Path { From = b, To = a, Dist = c });
            }

            var (Q, K) = Read2Longs();
            K--;//インデックス変換
            var distK = new long[N];
            distK[K] = 0;
            var q = new Queue<Path>();

            var distsOfK = dists[(int)K];
            foreach (var item in distsOfK)
            {
                distK[item.To] = item.Dist;

                foreach (var d in dists[(int)item.To])
                {
                    if (d.To == K) continue;
                    q.Enqueue(d);
                }
            }

            while (q.Count > 0)
            {
                var dq = q.Dequeue();
                distK[dq.To] = distK[dq.From] + dq.Dist;

                var removes = new List<int>();
                var distsOfTo = dists[(int)dq.To];
                foreach (var item in distsOfTo)
                {
                    if (distK[item.To] != 0)
                    {
                        removes.Add(distsOfTo.IndexOf(item));
                        continue;
                    }
                    q.Enqueue(item);
                }

                foreach (var remove in removes.OrderByDescending(x => x))
                {
                    distsOfTo.RemoveAt(remove);
                }
            }

            var sb = new StringBuilder();
            for (var i = 0; i < Q; i++)
            {
                var (x, y) = Read2Longs();
                x--; y--;//インデックス変換
                var d = distK[x] + distK[y];
                sb.AppendLine(d.ToString());
            }

            return sb.ToString().Trim();
        }

        private class Path
        {
            public long From { get; set; }
            public long To { get; set; }
            public long Dist { get; set; }
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 74348