module.exports=function(r){var e={};function t(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=r,t.c=e,t.d=function(r,e,n){t.o(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:n})},t.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},t.t=function(r,e){if(1&e&&(r=t(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var o in r)t.d(n,o,function(e){return r[e]}.bind(null,o));return n},t.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(e,"a",e),e},t.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},t.p="",t(t.s=0)}([function(r,e,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(r,e,t){"use strict";function n(r,e){return function(r){if(Array.isArray(r))return r}(r)||function(r,e){var t=[],n=!0,o=!1,u=void 0;try{for(var i,f=r[Symbol.iterator]();!(n=(i=f.next()).done)&&(t.push(i.value),!e||t.length!==e);n=!0);}catch(r){o=!0,u=r}finally{try{n||null==f.return||f.return()}finally{if(o)throw u}}return t}(r,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}r.exports=function(r){for(var e=Number(r[0]),t=new Array(e),o=0;o<e;o++)t[o]=[];for(var u=n(r[e].split(" ").map(function(r){return Number(r)}),2),i=u[0],f=u[1],a=0;a<e-1;a++){var l=n(r[a+1].split(" ").map(function(r){return Number(r)}),3),c=l[0],p=l[1],s=l[2];p!=f&&t[c-1].push({v:p-1,c:s}),c!=f&&t[p-1].push({v:c-1,c:s})}for(var v=new Array(e).fill(-1),d=[{v:f-1,s:0}];d.length>0;){var y=d.pop();v[y.v]=y.s;for(var b=t[y.v].length,m=0;m<b;m++){var h=t[y.v][m];-1==v[h.v]&&d.push({v:h.v,s:y.s+h.c})}}for(var g=0;g<i;g++){var x=n(r[g+e+1].split(" ").map(function(r){return Number(r)}),2),j=x[0],O=x[1],S=v[j-1]+v[O-1];console.log(S)}}},function(r,e){r.exports=require("fs")}]);