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