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