# -*- coding: utf-8 -*-
from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int,input().split())
  
d = [[0 for i in range(N)] for j in range(N)] 
for i in range(M):
    x,y,z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z
for i in range(N):
    d[i][i] = 0

d = floyd_warshall(d, directed = False)
LN = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    for j in range(N):
        if d[i][j] <= L:
            LN[i][j] = 1
            LN[j][i] = 1

LN = floyd_warshall(LN, directed = False)    
s = []
t = []
Q = int(input())
for i in range(Q):
    s1, t1 = map(int,input().split())
    s.append(s1)
    t.append(t1)
for i in range(Q):
    if LN[s[i]-1][t[i]-1] == float("inf"):
        print(-1)
    else:
        print(int(LN[s[i]-1][t[i]-1]-1)) from scipy.sparse.csgraph import floyd_warshall N, M, L = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L [0 for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [0 for i in range(N)] d = [[0 for i in range(N)] for j in range(N)] d [[0 for i in range(N)] for j in range(N)] for i in range(M):
    x,y,z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z i range(M) range M x,y,z = map(int,input().split()) x map(int,input().split()) map int input().split() ().split () input split y z d[x-1][y-1] = z d[x-1][y-1] [x-1] d x-1 x 1 y-1 y 1 z d[y-1][x-1] = z d[y-1][x-1] [y-1] d y-1 y 1 x-1 x 1 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 d = floyd_warshall(d, directed = False) d floyd_warshall(d, directed = False) floyd_warshall d directed = False directed False [0 for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [0 for i in range(N)] LN = [[0 for i in range(N)] for j in range(N)] LN [[0 for i in range(N)] for j in range(N)] for i in range(N):
    for j in range(N):
        if d[i][j] <= L:
            LN[i][j] = 1
            LN[j][i] = 1 i range(N) range N for j in range(N):
        if d[i][j] <= L:
            LN[i][j] = 1
            LN[j][i] = 1 j range(N) range N if d[i][j] <= L:
            LN[i][j] = 1
            LN[j][i] = 1 d[i][j] <= L d[i][j] [i] d i j L LN[i][j] = 1 LN[i][j] [i] LN i j 1 LN[j][i] = 1 LN[j][i] [j] LN j i 1 LN = floyd_warshall(LN, directed = False) LN floyd_warshall(LN, directed = False) floyd_warshall LN directed = False directed False s = [] s [] t = [] t [] Q = int(input()) Q int(input()) int input() input for i in range(Q):
    s1, t1 = map(int,input().split())
    s.append(s1)
    t.append(t1) i range(Q) range Q s1, t1 = map(int,input().split()) s1 map(int,input().split()) map int input().split() ().split () input split t1 s.append(s1) s.append s append s1 t.append(t1) t.append t append t1 for i in range(Q):
    if LN[s[i]-1][t[i]-1] == float("inf"):
        print(-1)
    else:
        print(int(LN[s[i]-1][t[i]-1]-1)) i range(Q) range Q if LN[s[i]-1][t[i]-1] == float("inf"):
        print(-1)
    else:
        print(int(LN[s[i]-1][t[i]-1]-1)) LN[s[i]-1][t[i]-1] == float("inf") LN[s[i]-1][t[i]-1] [s[i]-1] LN s[i]-1 s[i] s i 1 t[i]-1 t[i] t i 1 float("inf") float "inf" print(-1) print -1 print(int(LN[s[i]-1][t[i]-1]-1)) print int(LN[s[i]-1][t[i]-1]-1) int LN[s[i]-1][t[i]-1]-1 LN[s[i]-1][t[i]-1] [s[i]-1] LN s[i]-1 s[i] s i 1 t[i]-1 t[i] t i 1 1 d = [[0 for i in range(N)] for j in range(N)] [[0 for i in range(N)] for j in range(N)] d L = map(int,input().split()) map(int,input().split()) L t1 = map(int,input().split()) map(int,input().split()) t1 y,z = map(int,input().split()) map(int,input().split()) y Q = int(input()) int(input()) Q x,y,z = map(int,input().split()) map(int,input().split()) x LN = [[0 for i in range(N)] for j in range(N)] [[0 for i in range(N)] for j in range(N)] LN s = [] [] s M, L = map(int,input().split()) map(int,input().split()) M d = floyd_warshall(d, directed = False) floyd_warshall(d, directed = False) d z = map(int,input().split()) map(int,input().split()) z LN = floyd_warshall(LN, directed = False) floyd_warshall(LN, directed = False) LN s1, t1 = map(int,input().split()) map(int,input().split()) s1 N, M, L = map(int,input().split()) map(int,input().split()) N t = [] [] t
# -*- coding: utf-8 -*-
from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int,input().split())
  
d = [[0 for i in range(N)] for j in range(N)] 
for i in range(M):
    x,y,z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z
for i in range(N):
    d[i][i] = 0

d = floyd_warshall(d, directed = False)
LN = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    for j in range(N):
        if d[i][j] <= L:
            LN[i][j] = 1
            LN[j][i] = 1

LN = floyd_warshall(LN, directed = False)    
s = []
t = []
Q = int(input())
for i in range(Q):
    s1, t1 = map(int,input().split())
    s.append(s1)
    t.append(t1)
for i in range(Q):
    if LN[s[i]-1][t[i]-1] == float("inf"):
        print(-1)
    else:
        print(int(LN[s[i]-1][t[i]-1]-1))