import sys
input = sys.stdin.readline
N,M,L = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]
Q = int(input())
ST = [tuple(map(int,input().split())) for i in range(Q)]

INF = 10**20
g = [[INF]*N for _ in range(N)]
for a,b,c in ABC:
    a,b = a-1,b-1
    g[a][b] = g[b][a] = c
for i in range(N):
    g[i][i] = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            if g[i][j] > g[i][k] + g[k][j]:
                g[i][j] = g[i][k] + g[k][j]

h = [[N]*N for _ in range(N)]
for i in range(N-1):
    for j in range(i+1,N):
        if g[i][j] <= L:
            h[i][j] = h[j][i] = 1
for i in range(N):
    h[i][i] = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            if h[i][j] > h[i][k] + h[k][j]:
                h[i][j] = h[i][k] + h[k][j]

ans = []
for s,t in ST:
    s,t = s-1,t-1
    if h[s][t] == N:
        ans.append(-1)
    else:
        ans.append(h[s][t] - 1)
print(*ans, sep='\n') import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N,M,L = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L tuple(map(int,input().split())) for i in range(M) for i in range(M) i range(M) range M for i in range(M) tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split ABC = [tuple(map(int,input().split())) for i in range(M)] ABC [tuple(map(int,input().split())) for i in range(M)] Q = int(input()) Q int(input()) int input() input tuple(map(int,input().split())) for i in range(Q) for i in range(Q) i range(Q) range Q for i in range(Q) tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split ST = [tuple(map(int,input().split())) for i in range(Q)] ST [tuple(map(int,input().split())) for i in range(Q)] INF = 10**20 INF 10**20 10 20 [INF]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF]*N [INF] INF N g = [[INF]*N for _ in range(N)] g [[INF]*N for _ in range(N)] for a,b,c in ABC:
    a,b = a-1,b-1
    g[a][b] = g[b][a] = c a b c ABC a,b = a-1,b-1 a a-1 a 1 b b-1 b 1 g[a][b] = g[b][a] = c g[a][b] [a] g a b c = g[b][a] = c g[b][a] [b] g b a c for i in range(N):
    g[i][i] = 0 i range(N) range N g[i][i] = 0 g[i][i] [i] g i i 0 for k in range(N):
    for i in range(N):
        for j in range(N):
            if g[i][j] > g[i][k] + g[k][j]:
                g[i][j] = g[i][k] + g[k][j] k range(N) range N for i in range(N):
        for j in range(N):
            if g[i][j] > g[i][k] + g[k][j]:
                g[i][j] = g[i][k] + g[k][j] i range(N) range N for j in range(N):
            if g[i][j] > g[i][k] + g[k][j]:
                g[i][j] = g[i][k] + g[k][j] j range(N) range N if g[i][j] > g[i][k] + g[k][j]:
                g[i][j] = g[i][k] + g[k][j] g[i][j] > g[i][k] + g[k][j] g[i][j] [i] g i j g[i][k] + g[k][j] g[i][k] [i] g i k g[k][j] [k] g k j g[i][j] = g[i][k] + g[k][j] g[i][j] [i] g i j g[i][k] + g[k][j] g[i][k] [i] g i k g[k][j] [k] g k j [N]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [N]*N [N] N N h = [[N]*N for _ in range(N)] h [[N]*N for _ in range(N)] for i in range(N-1):
    for j in range(i+1,N):
        if g[i][j] <= L:
            h[i][j] = h[j][i] = 1 i range(N-1) range N-1 N 1 for j in range(i+1,N):
        if g[i][j] <= L:
            h[i][j] = h[j][i] = 1 j range(i+1,N) range i+1 i 1 N if g[i][j] <= L:
            h[i][j] = h[j][i] = 1 g[i][j] <= L g[i][j] [i] g i j L h[i][j] = h[j][i] = 1 h[i][j] [i] h i j 1 = h[j][i] = 1 h[j][i] [j] h j i 1 for i in range(N):
    h[i][i] = 0 i range(N) range N h[i][i] = 0 h[i][i] [i] h i i 0 for k in range(N):
    for i in range(N):
        for j in range(N):
            if h[i][j] > h[i][k] + h[k][j]:
                h[i][j] = h[i][k] + h[k][j] k range(N) range N for i in range(N):
        for j in range(N):
            if h[i][j] > h[i][k] + h[k][j]:
                h[i][j] = h[i][k] + h[k][j] i range(N) range N for j in range(N):
            if h[i][j] > h[i][k] + h[k][j]:
                h[i][j] = h[i][k] + h[k][j] j range(N) range N if h[i][j] > h[i][k] + h[k][j]:
                h[i][j] = h[i][k] + h[k][j] h[i][j] > h[i][k] + h[k][j] h[i][j] [i] h i j h[i][k] + h[k][j] h[i][k] [i] h i k h[k][j] [k] h k j h[i][j] = h[i][k] + h[k][j] h[i][j] [i] h i j h[i][k] + h[k][j] h[i][k] [i] h i k h[k][j] [k] h k j ans = [] ans [] for s,t in ST:
    s,t = s-1,t-1
    if h[s][t] == N:
        ans.append(-1)
    else:
        ans.append(h[s][t] - 1) s t ST s,t = s-1,t-1 s s-1 s 1 t t-1 t 1 if h[s][t] == N:
        ans.append(-1)
    else:
        ans.append(h[s][t] - 1) h[s][t] == N h[s][t] [s] h s t N ans.append(-1) ans.append ans append -1 ans.append(h[s][t] - 1) ans.append ans append h[s][t] - 1 h[s][t] [s] h s t 1 print(*ans, sep='\n') print *ans ans sep='\n' sep '\n' ABC = [tuple(map(int,input().split())) for i in range(M)] [tuple(map(int,input().split())) for i in range(M)] ABC s,t = s-1,t-1 s-1 s M,L = map(int,input().split()) map(int,input().split()) M input = sys.stdin.readline sys.stdin.readline input a,b = a-1,b-1 a-1 a t = s-1,t-1 t-1 t L = map(int,input().split()) map(int,input().split()) L N,M,L = map(int,input().split()) map(int,input().split()) N ST = [tuple(map(int,input().split())) for i in range(Q)] [tuple(map(int,input().split())) for i in range(Q)] ST g = [[INF]*N for _ in range(N)] [[INF]*N for _ in range(N)] g Q = int(input()) int(input()) Q b = a-1,b-1 b-1 b INF = 10**20 10**20 INF h = [[N]*N for _ in range(N)] [[N]*N for _ in range(N)] h ans = [] [] ans
import sys
input = sys.stdin.readline
N,M,L = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]
Q = int(input())
ST = [tuple(map(int,input().split())) for i in range(Q)]

INF = 10**20
g = [[INF]*N for _ in range(N)]
for a,b,c in ABC:
    a,b = a-1,b-1
    g[a][b] = g[b][a] = c
for i in range(N):
    g[i][i] = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            if g[i][j] > g[i][k] + g[k][j]:
                g[i][j] = g[i][k] + g[k][j]

h = [[N]*N for _ in range(N)]
for i in range(N-1):
    for j in range(i+1,N):
        if g[i][j] <= L:
            h[i][j] = h[j][i] = 1
for i in range(N):
    h[i][i] = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            if h[i][j] > h[i][k] + h[k][j]:
                h[i][j] = h[i][k] + h[k][j]

ans = []
for s,t in ST:
    s,t = s-1,t-1
    if h[s][t] == N:
        ans.append(-1)
    else:
        ans.append(h[s][t] - 1)
print(*ans, sep='\n')