INF=10**15
N,M,L=map(int,input().split())
d=[[INF for i in range(N)] for j in range(N)]
d1=[[INF for i in range(N)] for j in range(N)]
for i in range(N):
    d[i][i]=0
for m in range(M):
    A,B,C=map(int,input().split())
    d[A-1][B-1]=C
    d[B-1][A-1]=C

for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])
for i in range(N):
        for j in range(N):
            if i!=j and d[i][j]<=L:
                d1[i][j]=1
                d1[j][i]=1
for k in range(N):
    for i in range(N):
        for j in range(N):
            d1[i][j]=min(d1[i][j],d1[i][k]+d1[k][j])

Q=int(input())
for _ in range(Q):
    s,t=map(int,input().split())
    dis=d1[s-1][t-1]
    if dis==INF:
        print(-1)
    else:
        print(dis-1)
 INF=10**15 INF 10**15 10 15 N,M,L=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L [INF for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [INF for i in range(N)] d=[[INF for i in range(N)] for j in range(N)] d [[INF for i in range(N)] for j in range(N)] [INF for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [INF for i in range(N)] d1=[[INF for i in range(N)] for j in range(N)] d1 [[INF for i in range(N)] for j in range(N)] for i in range(N):
    d[i][i]=0 i range(N) range N d[i][i]=0 d[i][i] [i] d i i 0 for m in range(M):
    A,B,C=map(int,input().split())
    d[A-1][B-1]=C
    d[B-1][A-1]=C m 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-1][B-1]=C d[A-1][B-1] [A-1] d A-1 A 1 B-1 B 1 C d[B-1][A-1]=C d[B-1][A-1] [B-1] d B-1 B 1 A-1 A 1 C for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j]) i range(N) range N for j in range(N):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j]) j range(N) range N 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 for i in range(N):
        for j in range(N):
            if i!=j and d[i][j]<=L:
                d1[i][j]=1
                d1[j][i]=1 i range(N) range N for j in range(N):
            if i!=j and d[i][j]<=L:
                d1[i][j]=1
                d1[j][i]=1 j range(N) range N if i!=j and d[i][j]<=L:
                d1[i][j]=1
                d1[j][i]=1 i!=j and d[i][j]<=L i!=j i j d[i][j]<=L d[i][j] [i] d i j L d1[i][j]=1 d1[i][j] [i] d1 i j 1 d1[j][i]=1 d1[j][i] [j] d1 j i 1 for k in range(N):
    for i in range(N):
        for j in range(N):
            d1[i][j]=min(d1[i][j],d1[i][k]+d1[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            d1[i][j]=min(d1[i][j],d1[i][k]+d1[k][j]) i range(N) range N for j in range(N):
            d1[i][j]=min(d1[i][j],d1[i][k]+d1[k][j]) j range(N) range N d1[i][j]=min(d1[i][j],d1[i][k]+d1[k][j]) d1[i][j] [i] d1 i j min(d1[i][j],d1[i][k]+d1[k][j]) min d1[i][j] [i] d1 i j d1[i][k]+d1[k][j] d1[i][k] [i] d1 i k d1[k][j] [k] d1 k j Q=int(input()) Q int(input()) int input() input for _ in range(Q):
    s,t=map(int,input().split())
    dis=d1[s-1][t-1]
    if dis==INF:
        print(-1)
    else:
        print(dis-1) _ range(Q) range Q s,t=map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t dis=d1[s-1][t-1] dis d1[s-1][t-1] [s-1] d1 s-1 s 1 t-1 t 1 if dis==INF:
        print(-1)
    else:
        print(dis-1) dis==INF dis INF print(-1) print -1 print(dis-1) print dis-1 dis 1 INF=10**15 10**15 INF t=map(int,input().split()) map(int,input().split()) t Q=int(input()) int(input()) Q d1=[[INF for i in range(N)] for j in range(N)] [[INF for i in range(N)] for j in range(N)] d1 N,M,L=map(int,input().split()) map(int,input().split()) N s,t=map(int,input().split()) map(int,input().split()) s L=map(int,input().split()) map(int,input().split()) L M,L=map(int,input().split()) map(int,input().split()) M C=map(int,input().split()) map(int,input().split()) C B,C=map(int,input().split()) map(int,input().split()) B dis=d1[s-1][t-1] d1[s-1][t-1] dis d=[[INF for i in range(N)] for j in range(N)] [[INF for i in range(N)] for j in range(N)] d A,B,C=map(int,input().split()) map(int,input().split()) A
INF=10**15
N,M,L=map(int,input().split())
d=[[INF for i in range(N)] for j in range(N)]
d1=[[INF for i in range(N)] for j in range(N)]
for i in range(N):
    d[i][i]=0
for m in range(M):
    A,B,C=map(int,input().split())
    d[A-1][B-1]=C
    d[B-1][A-1]=C

for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])
for i in range(N):
        for j in range(N):
            if i!=j and d[i][j]<=L:
                d1[i][j]=1
                d1[j][i]=1
for k in range(N):
    for i in range(N):
        for j in range(N):
            d1[i][j]=min(d1[i][j],d1[i][k]+d1[k][j])

Q=int(input())
for _ in range(Q):
    s,t=map(int,input().split())
    dis=d1[s-1][t-1]
    if dis==INF:
        print(-1)
    else:
        print(dis-1)

