import sys
input=sys.stdin.readline

def Warshall_Floyd(N,DIST):
    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])
    return DIST

N,M,L=map(int,input().split())

ABC=[list(map(int,input().split())) for i in range(M)]

Q=int(input())

st=[list(map(int,input().split())) for i in range(Q)]

inf=L+1
dist=[[inf]*N for i in range(N)]
for i in range(N):
    dist[i][i]=0
for A,B,C in ABC:
    dist[A-1][B-1]=min(dist[A-1][B-1],C)
    dist[B-1][A-1]=min(dist[B-1][A-1],C)

dist=Warshall_Floyd(N,dist)
dist_2=[[N+1]*N for i in range(N)]

for i in range(N):
    for j in range(N):
        if dist[i][j]<=L:
            dist_2[i][j]=1
            
for i in range(N):
    dist_2[i][i]=0

dist_2=Warshall_Floyd(N,dist_2)

for s,t in st:
    if dist_2[s-1][t-1]==N+1:
        print(-1)
    else:
        print(dist_2[s-1][t-1]-1) import sys sys input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def Warshall_Floyd(N,DIST):
    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])
    return DIST Warshall_Floyd 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 return DIST DIST N N DIST DIST 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 i in range(M) for i in range(M) i range(M) range M for i in range(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 i in range(M)] ABC [list(map(int,input().split())) for i in range(M)] Q=int(input()) Q int(input()) int input() input list(map(int,input().split())) for i in range(Q) for i in range(Q) i range(Q) range Q for i in range(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 i in range(Q)] st [list(map(int,input().split())) for i in range(Q)] inf=L+1 inf L+1 L 1 [inf]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [inf]*N [inf] inf N dist=[[inf]*N for i in range(N)] dist [[inf]*N for i 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 A,B,C in ABC:
    dist[A-1][B-1]=min(dist[A-1][B-1],C)
    dist[B-1][A-1]=min(dist[B-1][A-1],C) A B C ABC dist[A-1][B-1]=min(dist[A-1][B-1],C) dist[A-1][B-1] [A-1] dist A-1 A 1 B-1 B 1 min(dist[A-1][B-1],C) min dist[A-1][B-1] [A-1] dist A-1 A 1 B-1 B 1 C dist[B-1][A-1]=min(dist[B-1][A-1],C) dist[B-1][A-1] [B-1] dist B-1 B 1 A-1 A 1 min(dist[B-1][A-1],C) min dist[B-1][A-1] [B-1] dist B-1 B 1 A-1 A 1 C dist=Warshall_Floyd(N,dist) dist Warshall_Floyd(N,dist) Warshall_Floyd N dist [N+1]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [N+1]*N [N+1] N+1 N 1 N dist_2=[[N+1]*N for i in range(N)] dist_2 [[N+1]*N for i in range(N)] for i in range(N):
    for j in range(N):
        if dist[i][j]<=L:
            dist_2[i][j]=1
             i range(N) range N for j in range(N):
        if dist[i][j]<=L:
            dist_2[i][j]=1
             j range(N) range N if dist[i][j]<=L:
            dist_2[i][j]=1
             dist[i][j]<=L dist[i][j] [i] dist i j L dist_2[i][j]=1 dist_2[i][j] [i] dist_2 i j 1 for i in range(N):
    dist_2[i][i]=0 i range(N) range N dist_2[i][i]=0 dist_2[i][i] [i] dist_2 i i 0 dist_2=Warshall_Floyd(N,dist_2) dist_2 Warshall_Floyd(N,dist_2) Warshall_Floyd N dist_2 for s,t in st:
    if dist_2[s-1][t-1]==N+1:
        print(-1)
    else:
        print(dist_2[s-1][t-1]-1) s t st if dist_2[s-1][t-1]==N+1:
        print(-1)
    else:
        print(dist_2[s-1][t-1]-1) dist_2[s-1][t-1]==N+1 dist_2[s-1][t-1] [s-1] dist_2 s-1 s 1 t-1 t 1 N+1 N 1 print(-1) print -1 print(dist_2[s-1][t-1]-1) print dist_2[s-1][t-1]-1 dist_2[s-1][t-1] [s-1] dist_2 s-1 s 1 t-1 t 1 1 M,L=map(int,input().split()) map(int,input().split()) M dist=[[inf]*N for i in range(N)] [[inf]*N for i in range(N)] dist L=map(int,input().split()) map(int,input().split()) L input=sys.stdin.readline sys.stdin.readline input dist_2=Warshall_Floyd(N,dist_2) Warshall_Floyd(N,dist_2) dist_2 ABC=[list(map(int,input().split())) for i in range(M)] [list(map(int,input().split())) for i in range(M)] ABC st=[list(map(int,input().split())) for i in range(Q)] [list(map(int,input().split())) for i in range(Q)] st N,M,L=map(int,input().split()) map(int,input().split()) N inf=L+1 L+1 inf Q=int(input()) int(input()) Q dist=Warshall_Floyd(N,dist) Warshall_Floyd(N,dist) dist dist_2=[[N+1]*N for i in range(N)] [[N+1]*N for i in range(N)] dist_2 def Warshall_Floyd(N,DIST):
    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])
    return DIST def Warshall_Floyd(N,DIST):
    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])
    return DIST Warshall_Floyd
import sys
input=sys.stdin.readline

def Warshall_Floyd(N,DIST):
    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])
    return DIST

N,M,L=map(int,input().split())

ABC=[list(map(int,input().split())) for i in range(M)]

Q=int(input())

st=[list(map(int,input().split())) for i in range(Q)]

inf=L+1
dist=[[inf]*N for i in range(N)]
for i in range(N):
    dist[i][i]=0
for A,B,C in ABC:
    dist[A-1][B-1]=min(dist[A-1][B-1],C)
    dist[B-1][A-1]=min(dist[B-1][A-1],C)

dist=Warshall_Floyd(N,dist)
dist_2=[[N+1]*N for i in range(N)]

for i in range(N):
    for j in range(N):
        if dist[i][j]<=L:
            dist_2[i][j]=1
            
for i in range(N):
    dist_2[i][i]=0

dist_2=Warshall_Floyd(N,dist_2)

for s,t in st:
    if dist_2[s-1][t-1]==N+1:
        print(-1)
    else:
        print(dist_2[s-1][t-1]-1)