n,m,l=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
q=int(input())
st=[list(map(int,input().split())) for _ in [0]*q]
inf=10**12
dist=[[inf]*n for _ in [0]*n]
for i in range(n):
    dist[i][i]=0
for a,b,c in abc:
    dist[a-1][b-1]=c
    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])
inf=10**3
dist2=[[inf]*n for _ in [0]*n]
for i in range(n):
    for j in range(n):
        if dist[i][j]<=l:
            dist2[i][j]=1
for k in range(n):
    for i in range(n):
        for j in range(n):
            dist2[i][j]=min(dist2[i][j],dist2[i][k]+dist2[k][j])
for i in range(n):
    for j in range(n):
        if dist2[i][j]==inf:
            dist2[i][j]=-1
        else:
            dist2[i][j]-=1
for s,t in st:
    print(dist2[s-1][t-1]) n,m,l=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l list(map(int,input().split())) for _ in [0]*m for _ in [0]*m _ [0]*m [0] 0 m for _ in [0]*m list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split abc=[list(map(int,input().split())) for _ in [0]*m] abc [list(map(int,input().split())) for _ in [0]*m] q=int(input()) q int(input()) int input() input list(map(int,input().split())) for _ in [0]*q for _ in [0]*q _ [0]*q [0] 0 q for _ in [0]*q list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split st=[list(map(int,input().split())) for _ in [0]*q] st [list(map(int,input().split())) for _ in [0]*q] inf=10**12 inf 10**12 10 12 [inf]*n for _ in [0]*n for _ in [0]*n _ [0]*n [0] 0 n for _ in [0]*n [inf]*n [inf] inf n dist=[[inf]*n for _ in [0]*n] dist [[inf]*n for _ in [0]*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 a,b,c in abc:
    dist[a-1][b-1]=c
    dist[b-1][a-1]=c a b c abc dist[a-1][b-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 inf=10**3 inf 10**3 10 3 [inf]*n for _ in [0]*n for _ in [0]*n _ [0]*n [0] 0 n for _ in [0]*n [inf]*n [inf] inf n dist2=[[inf]*n for _ in [0]*n] dist2 [[inf]*n for _ in [0]*n] for i in range(n):
    for j in range(n):
        if dist[i][j]<=l:
            dist2[i][j]=1 i range(n) range n for j in range(n):
        if dist[i][j]<=l:
            dist2[i][j]=1 j range(n) range n if dist[i][j]<=l:
            dist2[i][j]=1 dist[i][j]<=l dist[i][j] [i] dist i j l dist2[i][j]=1 dist2[i][j] [i] dist2 i j 1 for k in range(n):
    for i in range(n):
        for j in range(n):
            dist2[i][j]=min(dist2[i][j],dist2[i][k]+dist2[k][j]) k range(n) range n for i in range(n):
        for j in range(n):
            dist2[i][j]=min(dist2[i][j],dist2[i][k]+dist2[k][j]) i range(n) range n for j in range(n):
            dist2[i][j]=min(dist2[i][j],dist2[i][k]+dist2[k][j]) j range(n) range n dist2[i][j]=min(dist2[i][j],dist2[i][k]+dist2[k][j]) dist2[i][j] [i] dist2 i j min(dist2[i][j],dist2[i][k]+dist2[k][j]) min dist2[i][j] [i] dist2 i j dist2[i][k]+dist2[k][j] dist2[i][k] [i] dist2 i k dist2[k][j] [k] dist2 k j for i in range(n):
    for j in range(n):
        if dist2[i][j]==inf:
            dist2[i][j]=-1
        else:
            dist2[i][j]-=1 i range(n) range n for j in range(n):
        if dist2[i][j]==inf:
            dist2[i][j]=-1
        else:
            dist2[i][j]-=1 j range(n) range n if dist2[i][j]==inf:
            dist2[i][j]=-1
        else:
            dist2[i][j]-=1 dist2[i][j]==inf dist2[i][j] [i] dist2 i j inf dist2[i][j]=-1 dist2[i][j] [i] dist2 i j -1 dist2[i][j]-=1 dist2[i][j] [i] dist2 i j 1 for s,t in st:
    print(dist2[s-1][t-1]) s t st print(dist2[s-1][t-1]) print dist2[s-1][t-1] [s-1] dist2 s-1 s 1 t-1 t 1 inf=10**3 10**3 inf abc=[list(map(int,input().split())) for _ in [0]*m] [list(map(int,input().split())) for _ in [0]*m] abc m,l=map(int,input().split()) map(int,input().split()) m l=map(int,input().split()) map(int,input().split()) l dist=[[inf]*n for _ in [0]*n] [[inf]*n for _ in [0]*n] dist st=[list(map(int,input().split())) for _ in [0]*q] [list(map(int,input().split())) for _ in [0]*q] st n,m,l=map(int,input().split()) map(int,input().split()) n q=int(input()) int(input()) q dist2=[[inf]*n for _ in [0]*n] [[inf]*n for _ in [0]*n] dist2 inf=10**12 10**12 inf
n,m,l=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
q=int(input())
st=[list(map(int,input().split())) for _ in [0]*q]
inf=10**12
dist=[[inf]*n for _ in [0]*n]
for i in range(n):
    dist[i][i]=0
for a,b,c in abc:
    dist[a-1][b-1]=c
    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])
inf=10**3
dist2=[[inf]*n for _ in [0]*n]
for i in range(n):
    for j in range(n):
        if dist[i][j]<=l:
            dist2[i][j]=1
for k in range(n):
    for i in range(n):
        for j in range(n):
            dist2[i][j]=min(dist2[i][j],dist2[i][k]+dist2[k][j])
for i in range(n):
    for j in range(n):
        if dist2[i][j]==inf:
            dist2[i][j]=-1
        else:
            dist2[i][j]-=1
for s,t in st:
    print(dist2[s-1][t-1])