module.exports=function(r){var t={};function e(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return r[n].call(i.exports,i,i.exports,e),i.l=!0,i.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 i in r)e.d(n,i,function(t){return r[t]}.bind(null,i));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){"use strict";var n=e(1);e(2)(n.readFileSync("/dev/stdin","utf8"))},function(r,t){r.exports=require("fs")},function(r,t,e){"use strict";var n=e(3),i=e(5);r.exports=function(r){var t=new n(r);i(t)}},function(r,t,e){"use strict";var n=e(4);r.exports=class{constructor(r){var t=r.trim().split(/\s+/g);this.inp=new n(t)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(r,t,e){"use strict";r.exports=class{constructor(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=r.length,this.items=r,this.ind=0}enq(r){this.size+=1,this.items.push(r)}deq(){var r=this.items[this.ind];return this.size-=1,this.ind+=1,r}clear(){this.items=[],this.size=0,this.ind=0}}},function(r,t,e){"use strict";var n=e(6);r.exports=function(r){for(var t=99999999999,e=r.in(),i=r.in(),o=r.in(),s=new Array(e),u=0;u<e;u++)s[u]=new Array(e).fill(t);for(var c=0;c<i;c++){var f=r.in(),a=r.in(),l=r.in();s[f-1][a-1]=l,s[a-1][f-1]=l}for(var p=n(s),v=0;v<e;v++)for(var d=0;d<e;d++){if(p[v][d]>t)throw new Error("ov");v!=d&&p[v][d]<=o&&(s[v][d]=1)}for(var h=n(s),y=r.in(),b=0;b<y;b++){var g=r.in(),m=r.in(),x=h[g-1][m-1];x==t?console.log(-1):console.log(x-1)}}},function(r,t,e){"use strict";r.exports=function(r){for(var t=r.length,e=[],n=0;n<t;n++)e.push(r[n].concat());for(var i=0;i<t;i++)for(var o=0;o<t;o++)for(var s=0;s<t;s++)e[o][s]>e[o][i]+e[i][s]&&(e[o][s]=e[o][i]+e[i][s]);return e}}]);