N, M, L = map(int, input().split())
dist = [[10**12] * N for _ in range(N)]
for i in range(N):
    dist[i][i] = 0
    
for _ in range(M):
    a, b, c = map(int, input().split())
    if c <= L:
    	dist[a-1][b-1] = dist[b-1][a-1] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

old_dist = [row[:] for row in dist]
for i in range(N):
    for j in range(N):
        if old_dist[i][j] <= L:
            dist[i][j] = 1
            
for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

Q = int(input())
for _ in range(Q):
    start, end= map(int, input().split())
    if dist[start-1][end-1] < 10**12:
    	print(dist[start-1][end-1] - 1)
    else:
        print(-1) N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L [10**12] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [10**12] * N [10**12] 10**12 10 12 N dist = [[10**12] * N for _ in range(N)] dist [[10**12] * N for _ in range(N)] for i in range(N):
    dist[i][i] = 0
     i range(N) range N dist[i][i] = 0 dist[i][i] [i] dist i i 0 for _ in range(M):
    a, b, c = map(int, input().split())
    if c <= L:
    	dist[a-1][b-1] = dist[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:
    	dist[a-1][b-1] = dist[b-1][a-1] = c c <= L c L dist[a-1][b-1] = dist[b-1][a-1] = c dist[a-1][b-1] [a-1] dist a-1 a 1 b-1 b 1 c = dist[b-1][a-1] = c dist[b-1][a-1] [b-1] dist b-1 b 1 a-1 a 1 c for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) i range(N) range N for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) j range(N) range N dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) dist[i][j] [i] dist i j min(dist[i][j], dist[i][k] + dist[k][j]) min dist[i][j] [i] dist i j dist[i][k] + dist[k][j] dist[i][k] [i] dist i k dist[k][j] [k] dist k j row[:] for row in dist for row in dist row dist for row in dist row[:] row : old_dist = [row[:] for row in dist] old_dist [row[:] for row in dist] for i in range(N):
    for j in range(N):
        if old_dist[i][j] <= L:
            dist[i][j] = 1
             i range(N) range N for j in range(N):
        if old_dist[i][j] <= L:
            dist[i][j] = 1
             j range(N) range N if old_dist[i][j] <= L:
            dist[i][j] = 1
             old_dist[i][j] <= L old_dist[i][j] [i] old_dist i j L dist[i][j] = 1 dist[i][j] [i] dist i j 1 for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) i range(N) range N for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) j range(N) range N dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) dist[i][j] [i] dist i j min(dist[i][j], dist[i][k] + dist[k][j]) min dist[i][j] [i] dist i j dist[i][k] + dist[k][j] dist[i][k] [i] dist i k dist[k][j] [k] dist k j Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    start, end= map(int, input().split())
    if dist[start-1][end-1] < 10**12:
    	print(dist[start-1][end-1] - 1)
    else:
        print(-1) _ range(Q) range Q start, end= map(int, input().split()) start map(int, input().split()) map int input().split() ().split () input split end if dist[start-1][end-1] < 10**12:
    	print(dist[start-1][end-1] - 1)
    else:
        print(-1) dist[start-1][end-1] < 10**12 dist[start-1][end-1] [start-1] dist start-1 start 1 end-1 end 1 10**12 10 12 print(dist[start-1][end-1] - 1) print dist[start-1][end-1] - 1 dist[start-1][end-1] [start-1] dist start-1 start 1 end-1 end 1 1 print(-1) print -1 start, end= map(int, input().split()) map(int, input().split()) start M, L = map(int, input().split()) map(int, input().split()) M L = map(int, input().split()) map(int, input().split()) L b, c = map(int, input().split()) map(int, input().split()) b old_dist = [row[:] for row in dist] [row[:] for row in dist] old_dist Q = int(input()) int(input()) Q dist = [[10**12] * N for _ in range(N)] [[10**12] * N for _ in range(N)] dist a, b, c = map(int, input().split()) map(int, input().split()) a c = map(int, input().split()) map(int, input().split()) c N, M, L = map(int, input().split()) map(int, input().split()) N end= map(int, input().split()) map(int, input().split()) end
N, M, L = map(int, input().split())
dist = [[10**12] * N for _ in range(N)]
for i in range(N):
    dist[i][i] = 0
    
for _ in range(M):
    a, b, c = map(int, input().split())
    if c <= L:
    	dist[a-1][b-1] = dist[b-1][a-1] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

old_dist = [row[:] for row in dist]
for i in range(N):
    for j in range(N):
        if old_dist[i][j] <= L:
            dist[i][j] = 1
            
for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

Q = int(input())
for _ in range(Q):
    start, end= map(int, input().split())
    if dist[start-1][end-1] < 10**12:
    	print(dist[start-1][end-1] - 1)
    else:
        print(-1)