import sys
input=sys.stdin.readline
inf=10**9+7
n,m,l=map(int,input().split())
D=[[inf]*(n+1) for _ in range(n+1)]
for _ in range(m):
    a,b,c=map(int,input().split())
    D[a][b]=c
    D[b][a]=c

for k in range(1,n+1):
    for i in range(1,n+1):
        for j in range(1,n+1):
            D[i][j]=min(D[i][j],D[i][k]+D[k][j])

DD=[[inf]*(n+1) for _ in range(n+1)]
for x in range(1,n+1):
    for y in range(1,n+1):
        if D[x][y]<=l:
            DD[x][y]=1

for k in range(1,n+1):
    for i in range(1,n+1):
        for j in range(1,n+1):
            DD[i][j]=min(DD[i][j],DD[i][k]+DD[k][j])

q=int(input())
for _ in range(q):
    s,t=map(int,input().split())
    if DD[s][t]==inf:
        print(-1)
    else:
        print(DD[s][t]-1) import sys sys input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline inf=10**9+7 inf 10**9+7 10**9 10 9 7 n,m,l=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l [inf]*(n+1) for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [inf]*(n+1) [inf] inf n+1 n 1 D=[[inf]*(n+1) for _ in range(n+1)] D [[inf]*(n+1) for _ in range(n+1)] for _ in range(m):
    a,b,c=map(int,input().split())
    D[a][b]=c
    D[b][a]=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 D[a][b]=c D[a][b] [a] D a b c D[b][a]=c D[b][a] [b] D b a c for k in range(1,n+1):
    for i in range(1,n+1):
        for j in range(1,n+1):
            D[i][j]=min(D[i][j],D[i][k]+D[k][j]) k range(1,n+1) range 1 n+1 n 1 for i in range(1,n+1):
        for j in range(1,n+1):
            D[i][j]=min(D[i][j],D[i][k]+D[k][j]) i range(1,n+1) range 1 n+1 n 1 for j in range(1,n+1):
            D[i][j]=min(D[i][j],D[i][k]+D[k][j]) j range(1,n+1) range 1 n+1 n 1 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 [inf]*(n+1) for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [inf]*(n+1) [inf] inf n+1 n 1 DD=[[inf]*(n+1) for _ in range(n+1)] DD [[inf]*(n+1) for _ in range(n+1)] for x in range(1,n+1):
    for y in range(1,n+1):
        if D[x][y]<=l:
            DD[x][y]=1 x range(1,n+1) range 1 n+1 n 1 for y in range(1,n+1):
        if D[x][y]<=l:
            DD[x][y]=1 y range(1,n+1) range 1 n+1 n 1 if D[x][y]<=l:
            DD[x][y]=1 D[x][y]<=l D[x][y] [x] D x y l DD[x][y]=1 DD[x][y] [x] DD x y 1 for k in range(1,n+1):
    for i in range(1,n+1):
        for j in range(1,n+1):
            DD[i][j]=min(DD[i][j],DD[i][k]+DD[k][j]) k range(1,n+1) range 1 n+1 n 1 for i in range(1,n+1):
        for j in range(1,n+1):
            DD[i][j]=min(DD[i][j],DD[i][k]+DD[k][j]) i range(1,n+1) range 1 n+1 n 1 for j in range(1,n+1):
            DD[i][j]=min(DD[i][j],DD[i][k]+DD[k][j]) j range(1,n+1) range 1 n+1 n 1 DD[i][j]=min(DD[i][j],DD[i][k]+DD[k][j]) DD[i][j] [i] DD i j min(DD[i][j],DD[i][k]+DD[k][j]) min DD[i][j] [i] DD i j DD[i][k]+DD[k][j] DD[i][k] [i] DD i k DD[k][j] [k] DD k j q=int(input()) q int(input()) int input() input for _ in range(q):
    s,t=map(int,input().split())
    if DD[s][t]==inf:
        print(-1)
    else:
        print(DD[s][t]-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 DD[s][t]==inf:
        print(-1)
    else:
        print(DD[s][t]-1) DD[s][t]==inf DD[s][t] [s] DD s t inf print(-1) print -1 print(DD[s][t]-1) print DD[s][t]-1 DD[s][t] [s] DD s t 1 input=sys.stdin.readline sys.stdin.readline input n,m,l=map(int,input().split()) map(int,input().split()) n DD=[[inf]*(n+1) for _ in range(n+1)] [[inf]*(n+1) for _ in range(n+1)] DD c=map(int,input().split()) map(int,input().split()) c a,b,c=map(int,input().split()) map(int,input().split()) a s,t=map(int,input().split()) map(int,input().split()) s t=map(int,input().split()) map(int,input().split()) t q=int(input()) int(input()) q l=map(int,input().split()) map(int,input().split()) l b,c=map(int,input().split()) map(int,input().split()) b inf=10**9+7 10**9+7 inf m,l=map(int,input().split()) map(int,input().split()) m D=[[inf]*(n+1) for _ in range(n+1)] [[inf]*(n+1) for _ in range(n+1)] D
import sys
input=sys.stdin.readline
inf=10**9+7
n,m,l=map(int,input().split())
D=[[inf]*(n+1) for _ in range(n+1)]
for _ in range(m):
    a,b,c=map(int,input().split())
    D[a][b]=c
    D[b][a]=c

for k in range(1,n+1):
    for i in range(1,n+1):
        for j in range(1,n+1):
            D[i][j]=min(D[i][j],D[i][k]+D[k][j])

DD=[[inf]*(n+1) for _ in range(n+1)]
for x in range(1,n+1):
    for y in range(1,n+1):
        if D[x][y]<=l:
            DD[x][y]=1

for k in range(1,n+1):
    for i in range(1,n+1):
        for j in range(1,n+1):
            DD[i][j]=min(DD[i][j],DD[i][k]+DD[k][j])

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