import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product

def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,m,l=map(int,input().split())
abc=[list(map(int,input().split())) for i in range(m)]
q=int(input())
st=[list(map(int,input().split())) for i in range(q)]

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

n,w = n,m #n:頂点数　w:辺の数

d = [[float("inf") for i in range(n)] for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(w):
    x,y,z = abc[i]
    x,y=x-1,y-1
    d[x][y] = z
    d[y][x] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
tmp=warshall_floyd(d)

newd = [[float("inf") for i in range(n)] for i in range(n)]

for i in range(n):
    for j in range(i+1,n):
        if d[i][j]<=l:
            newd[i][j]=1
            newd[j][i]=1
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０

tmp=warshall_floyd(newd)

for i in range(q):
    s,t=st[i]
    s,t=s-1,t-1

    print(newd[s][t]-1 if newd[s][t]!=float('inf') else -1) import bisect bisect import copy copy import heapq heapq import math math import sys sys from collections import * from itertools import accumulate, combinations, permutations, product def input():
    return sys.stdin.readline()[:-1] input return sys.stdin.readline()[:-1] sys.stdin.readline()[:-1] sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline :-1 -1 def ruiseki(lst):
    return [0]+list(accumulate(lst)) ruiseki return [0]+list(accumulate(lst)) [0]+list(accumulate(lst)) [0] 0 list(accumulate(lst)) list accumulate(lst) accumulate lst lst lst mod=pow(10,9)+7 mod pow(10,9)+7 pow(10,9) pow 10 9 7 chr(ord('a') + i) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) chr(ord('a') + i) chr ord('a') + i ord('a') ord 'a' i al=[chr(ord('a') + i) for i in range(26)] al [chr(ord('a') + i) for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] direction [[1,0],[0,1],[-1,0],[0,-1]] [1,0] 1 0 [0,1] 0 1 [-1,0] -1 0 [0,-1] 0 -1 n,m,l=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l list(map(int,input().split())) for i in range(m) for i in range(m) i range(m) range m for i in range(m) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split abc=[list(map(int,input().split())) for i in range(m)] abc [list(map(int,input().split())) for i in range(m)] q=int(input()) q int(input()) int input() input list(map(int,input().split())) for i in range(q) for i in range(q) i range(q) range q for i in range(q) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split st=[list(map(int,input().split())) for i in range(q)] st [list(map(int,input().split())) for i in range(q)] def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d warshall_floyd for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
     k range(n) range n for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
     i range(n) range n for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
     j range(n) range n d[i][j] = min(d[i][j],d[i][k] + d[k][j]) d[i][j] [i] d i j min(d[i][j],d[i][k] + d[k][j]) min d[i][j] [i] d i j d[i][k] + d[k][j] d[i][k] [i] d i k d[k][j] [k] d k j return d d d d n,w = n,m n n w m [float("inf") for i in range(n)] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [float("inf") for i in range(n)] d = [[float("inf") for i in range(n)] for i in range(n)] d [[float("inf") for i in range(n)] for i in range(n)] for i in range(w):
    x,y,z = abc[i]
    x,y=x-1,y-1
    d[x][y] = z
    d[y][x] = z i range(w) range w x,y,z = abc[i] x abc[i] abc i y z x,y=x-1,y-1 x x-1 x 1 y y-1 y 1 d[x][y] = z d[x][y] [x] d x y z d[y][x] = z d[y][x] [y] d y x z for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０ i range(n) range n d[i][i] = 0 d[i][i] [i] d i i 0 tmp=warshall_floyd(d) tmp warshall_floyd(d) warshall_floyd d [float("inf") for i in range(n)] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [float("inf") for i in range(n)] newd = [[float("inf") for i in range(n)] for i in range(n)] newd [[float("inf") for i in range(n)] for i in range(n)] for i in range(n):
    for j in range(i+1,n):
        if d[i][j]<=l:
            newd[i][j]=1
            newd[j][i]=1 i range(n) range n for j in range(i+1,n):
        if d[i][j]<=l:
            newd[i][j]=1
            newd[j][i]=1 j range(i+1,n) range i+1 i 1 n if d[i][j]<=l:
            newd[i][j]=1
            newd[j][i]=1 d[i][j]<=l d[i][j] [i] d i j l newd[i][j]=1 newd[i][j] [i] newd i j 1 newd[j][i]=1 newd[j][i] [j] newd j i 1 for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０ i range(n) range n d[i][i] = 0 d[i][i] [i] d i i 0 tmp=warshall_floyd(newd) tmp warshall_floyd(newd) warshall_floyd newd for i in range(q):
    s,t=st[i]
    s,t=s-1,t-1

    print(newd[s][t]-1 if newd[s][t]!=float('inf') else -1) i range(q) range q s,t=st[i] s st[i] st i t s,t=s-1,t-1 s s-1 s 1 t t-1 t 1 print(newd[s][t]-1 if newd[s][t]!=float('inf') else -1) print newd[s][t]-1 if newd[s][t]!=float('inf') else -1 newd[s][t]!=float('inf') newd[s][t] [s] newd s t float('inf') float 'inf' newd[s][t]-1 newd[s][t] [s] newd s t 1 -1 st=[list(map(int,input().split())) for i in range(q)] [list(map(int,input().split())) for i in range(q)] st z = abc[i] abc[i] z def input():
    return sys.stdin.readline()[:-1] def input():
    return sys.stdin.readline()[:-1] input s,t=s-1,t-1 s-1 s n,w = n,m n n def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d warshall_floyd y=x-1,y-1 y-1 y direction=[[1,0],[0,1],[-1,0],[0,-1]] [[1,0],[0,1],[-1,0],[0,-1]] direction def ruiseki(lst):
    return [0]+list(accumulate(lst)) def ruiseki(lst):
    return [0]+list(accumulate(lst)) ruiseki q=int(input()) int(input()) q t=s-1,t-1 t-1 t m,l=map(int,input().split()) map(int,input().split()) m tmp=warshall_floyd(d) warshall_floyd(d) tmp x,y,z = abc[i] abc[i] x d = [[float("inf") for i in range(n)] for i in range(n)] [[float("inf") for i in range(n)] for i in range(n)] d l=map(int,input().split()) map(int,input().split()) l s,t=st[i] st[i] s w = n,m m w tmp=warshall_floyd(newd) warshall_floyd(newd) tmp mod=pow(10,9)+7 pow(10,9)+7 mod t=st[i] st[i] t abc=[list(map(int,input().split())) for i in range(m)] [list(map(int,input().split())) for i in range(m)] abc al=[chr(ord('a') + i) for i in range(26)] [chr(ord('a') + i) for i in range(26)] al newd = [[float("inf") for i in range(n)] for i in range(n)] [[float("inf") for i in range(n)] for i in range(n)] newd x,y=x-1,y-1 x-1 x n,m,l=map(int,input().split()) map(int,input().split()) n y,z = abc[i] abc[i] y
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product

def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,m,l=map(int,input().split())
abc=[list(map(int,input().split())) for i in range(m)]
q=int(input())
st=[list(map(int,input().split())) for i in range(q)]

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

n,w = n,m #n:頂点数　w:辺の数

d = [[float("inf") for i in range(n)] for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(w):
    x,y,z = abc[i]
    x,y=x-1,y-1
    d[x][y] = z
    d[y][x] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
tmp=warshall_floyd(d)

newd = [[float("inf") for i in range(n)] for i in range(n)]

for i in range(n):
    for j in range(i+1,n):
        if d[i][j]<=l:
            newd[i][j]=1
            newd[j][i]=1
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０

tmp=warshall_floyd(newd)

for i in range(q):
    s,t=st[i]
    s,t=s-1,t-1

    print(newd[s][t]-1 if newd[s][t]!=float('inf') else -1)