module.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){var r=n(1),i=new(n(2))(r.readFileSync("/dev/stdin","utf8").split(/\s+/g));n(4)(i)},function(e,t){e.exports=require("fs")},function(e,t,n){var r=n(3);e.exports=class{constructor(e){this.inp=new r(e)}n(){return this.inp.deq()}ni(){return parseInt(this.inp.deq(),10)}add(e){this.inp.enq(e)}}},function(e,t,n){"use strict";e.exports=class{constructor(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=e.length,this.items=e,this.ind=0}enq(e){this.size+=1,this.items.push(e)}deq(){var e=this.items[this.ind];return this.size-=1,this.ind+=1,e}}},function(e,t,n){"use strict";e.exports=function(e){for(var t=e.ni(),n=new Array(t),r=0;r<t;r++)n[r]=[];for(var i=0;i<t-1;i++){var o=e.ni(),s=e.ni(),u=e.ni();n[o-1].push([s-1,u]),n[s-1].push([o-1,u])}for(var f=e.ni(),a=e.ni(),c=new Array(t).fill(-1),l=[[a-1,0]];l.length>0;)for(var p=l.pop(),d=n[p[0]].length,v=0;v<d;v++){var h=n[p[0]][v];if(-1==c[h[0]]){var y=p[1]+h[1];c[h[0]]=y,l.push([h[0],y])}}for(var b=0;b<f;b++){var g=e.ni()-1,m=e.ni()-1,x=c[g]+c[m];console.log(x)}}}]);