import sys
from scipy.sparse.csgraph import floyd_warshall
input = sys.stdin.readline

INF = float('inf')
n, m, l = map(int, input().split())
table_1 = [ [0 for _ in range(n) ] for _ in range(n) ]
table_2 = [ [0 for _ in range(n) ] for _ in range(n) ]

for _ in range(m):
    a, b, c = map(int, input().split())
    if c<=l:
        table_1[a-1][b-1] = c
        table_1[b-1][a-1] = c

table_1 = floyd_warshall(csgraph=table_1, directed=False)

for i in range(n):
    for j in range(i+1, n):
        if table_1[i][j] <= l:
            table_2[i][j] = 1
            table_2[j][i] = 1

table_2 = floyd_warshall(csgraph=table_2, directed=False)

q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    if table_2[s-1][t-1] == INF:
        print(-1)
    else:
        print(int(table_2[s-1][t-1])-1) import sys sys from scipy.sparse.csgraph import floyd_warshall input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline INF = float('inf') INF float('inf') float 'inf' n, m, l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l [0 for _ in range(n) ] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0 for _ in range(n) ] table_1 = [ [0 for _ in range(n) ] for _ in range(n) ] table_1 [ [0 for _ in range(n) ] for _ in range(n) ] [0 for _ in range(n) ] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0 for _ in range(n) ] table_2 = [ [0 for _ in range(n) ] for _ in range(n) ] table_2 [ [0 for _ in range(n) ] for _ in range(n) ] for _ in range(m):
    a, b, c = map(int, input().split())
    if c<=l:
        table_1[a-1][b-1] = c
        table_1[b-1][a-1] = c _ range(m) range m a, b, c = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b c if c<=l:
        table_1[a-1][b-1] = c
        table_1[b-1][a-1] = c c<=l c l table_1[a-1][b-1] = c table_1[a-1][b-1] [a-1] table_1 a-1 a 1 b-1 b 1 c table_1[b-1][a-1] = c table_1[b-1][a-1] [b-1] table_1 b-1 b 1 a-1 a 1 c table_1 = floyd_warshall(csgraph=table_1, directed=False) table_1 floyd_warshall(csgraph=table_1, directed=False) floyd_warshall csgraph=table_1 csgraph table_1 directed=False directed False for i in range(n):
    for j in range(i+1, n):
        if table_1[i][j] <= l:
            table_2[i][j] = 1
            table_2[j][i] = 1 i range(n) range n for j in range(i+1, n):
        if table_1[i][j] <= l:
            table_2[i][j] = 1
            table_2[j][i] = 1 j range(i+1, n) range i+1 i 1 n if table_1[i][j] <= l:
            table_2[i][j] = 1
            table_2[j][i] = 1 table_1[i][j] <= l table_1[i][j] [i] table_1 i j l table_2[i][j] = 1 table_2[i][j] [i] table_2 i j 1 table_2[j][i] = 1 table_2[j][i] [j] table_2 j i 1 table_2 = floyd_warshall(csgraph=table_2, directed=False) table_2 floyd_warshall(csgraph=table_2, directed=False) floyd_warshall csgraph=table_2 csgraph table_2 directed=False directed False q = int(input()) q int(input()) int input() input for _ in range(q):
    s, t = map(int, input().split())
    if table_2[s-1][t-1] == INF:
        print(-1)
    else:
        print(int(table_2[s-1][t-1])-1) _ range(q) range q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t if table_2[s-1][t-1] == INF:
        print(-1)
    else:
        print(int(table_2[s-1][t-1])-1) table_2[s-1][t-1] == INF table_2[s-1][t-1] [s-1] table_2 s-1 s 1 t-1 t 1 INF print(-1) print -1 print(int(table_2[s-1][t-1])-1) print int(table_2[s-1][t-1])-1 int(table_2[s-1][t-1]) int table_2[s-1][t-1] [s-1] table_2 s-1 s 1 t-1 t 1 1 table_1 = [ [0 for _ in range(n) ] for _ in range(n) ] [ [0 for _ in range(n) ] for _ in range(n) ] table_1 input = sys.stdin.readline sys.stdin.readline input l = map(int, input().split()) map(int, input().split()) l table_2 = floyd_warshall(csgraph=table_2, directed=False) floyd_warshall(csgraph=table_2, directed=False) table_2 q = int(input()) int(input()) q s, t = map(int, input().split()) map(int, input().split()) s table_1 = floyd_warshall(csgraph=table_1, directed=False) floyd_warshall(csgraph=table_1, directed=False) table_1 n, m, l = map(int, input().split()) map(int, input().split()) n b, c = map(int, input().split()) map(int, input().split()) b c = map(int, input().split()) map(int, input().split()) c table_2 = [ [0 for _ in range(n) ] for _ in range(n) ] [ [0 for _ in range(n) ] for _ in range(n) ] table_2 m, l = map(int, input().split()) map(int, input().split()) m t = map(int, input().split()) map(int, input().split()) t a, b, c = map(int, input().split()) map(int, input().split()) a INF = float('inf') float('inf') INF
import sys
from scipy.sparse.csgraph import floyd_warshall
input = sys.stdin.readline

INF = float('inf')
n, m, l = map(int, input().split())
table_1 = [ [0 for _ in range(n) ] for _ in range(n) ]
table_2 = [ [0 for _ in range(n) ] for _ in range(n) ]

for _ in range(m):
    a, b, c = map(int, input().split())
    if c<=l:
        table_1[a-1][b-1] = c
        table_1[b-1][a-1] = c

table_1 = floyd_warshall(csgraph=table_1, directed=False)

for i in range(n):
    for j in range(i+1, n):
        if table_1[i][j] <= l:
            table_2[i][j] = 1
            table_2[j][i] = 1

table_2 = floyd_warshall(csgraph=table_2, directed=False)

q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    if table_2[s-1][t-1] == INF:
        print(-1)
    else:
        print(int(table_2[s-1][t-1])-1)