N,M,L=map(int,input().split())
A=[[] for i in range(N)]
for i in range(M):
    a,b,c=map(int,input().split())
    A[a-1].append((b-1,c))
    A[b-1].append((a-1,c))
d=[[100000000001]*N for i in range(N)]
for i in range(N):
    d[i][i]=0
for i in range(N):
    for to,cost in A[i]:
        d[i][to] = cost
for k in range(N):
    for i in range(N):
        for j in range(N):
            if d[i][k] != 100000000001 and d[k][j] != 100000000001:
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
B=[[] for i in range(N)]
for i in range(N):
    for j in range(N):
        if d[i][j]<=L:
            B[i].append((j,1))
times=[[100000000001]*N for i in range(N)]
for i in range(N):
    times[i][i]=0
for i in range(N):
    for to,cost in B[i]:
        times[i][to] = cost
for k in range(N):
    for i in range(N):
        for j in range(N):
            if times[i][k] != 100000000001 and times[k][j] != 100000000001:
                times[i][j] = min(times[i][j], times[i][k] + times[k][j])
Q=int(input())
for i in range(Q):
    s,t=map(int,input().split())
    if times[s-1][t-1]!=100000000001:
    	print(times[s-1][t-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 [] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [] A=[[] for i in range(N)] A [[] for i in range(N)] for i in range(M):
    a,b,c=map(int,input().split())
    A[a-1].append((b-1,c))
    A[b-1].append((a-1,c)) i 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 A[a-1].append((b-1,c)) [a-1].append [a-1] A a-1 a 1 append (b-1,c) b-1 b 1 c A[b-1].append((a-1,c)) [b-1].append [b-1] A b-1 b 1 append (a-1,c) a-1 a 1 c [100000000001]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [100000000001]*N [100000000001] 100000000001 N d=[[100000000001]*N for i in range(N)] d [[100000000001]*N for i 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 i in range(N):
    for to,cost in A[i]:
        d[i][to] = cost i range(N) range N for to,cost in A[i]:
        d[i][to] = cost to cost A[i] A i d[i][to] = cost d[i][to] [i] d i to cost for k in range(N):
    for i in range(N):
        for j in range(N):
            if d[i][k] != 100000000001 and d[k][j] != 100000000001:
                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):
            if d[i][k] != 100000000001 and d[k][j] != 100000000001:
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]) i range(N) range N for j in range(N):
            if d[i][k] != 100000000001 and d[k][j] != 100000000001:
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]) j range(N) range N if d[i][k] != 100000000001 and d[k][j] != 100000000001:
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]) d[i][k] != 100000000001 and d[k][j] != 100000000001 d[i][k] != 100000000001 d[i][k] [i] d i k 100000000001 d[k][j] != 100000000001 d[k][j] [k] d k j 100000000001 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 i in range(N) i range(N) range N for i in range(N) [] B=[[] for i in range(N)] B [[] for i in range(N)] for i in range(N):
    for j in range(N):
        if d[i][j]<=L:
            B[i].append((j,1)) i range(N) range N for j in range(N):
        if d[i][j]<=L:
            B[i].append((j,1)) j range(N) range N if d[i][j]<=L:
            B[i].append((j,1)) d[i][j]<=L d[i][j] [i] d i j L B[i].append((j,1)) [i].append [i] B i append (j,1) j 1 [100000000001]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [100000000001]*N [100000000001] 100000000001 N times=[[100000000001]*N for i in range(N)] times [[100000000001]*N for i in range(N)] for i in range(N):
    times[i][i]=0 i range(N) range N times[i][i]=0 times[i][i] [i] times i i 0 for i in range(N):
    for to,cost in B[i]:
        times[i][to] = cost i range(N) range N for to,cost in B[i]:
        times[i][to] = cost to cost B[i] B i times[i][to] = cost times[i][to] [i] times i to cost for k in range(N):
    for i in range(N):
        for j in range(N):
            if times[i][k] != 100000000001 and times[k][j] != 100000000001:
                times[i][j] = min(times[i][j], times[i][k] + times[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            if times[i][k] != 100000000001 and times[k][j] != 100000000001:
                times[i][j] = min(times[i][j], times[i][k] + times[k][j]) i range(N) range N for j in range(N):
            if times[i][k] != 100000000001 and times[k][j] != 100000000001:
                times[i][j] = min(times[i][j], times[i][k] + times[k][j]) j range(N) range N if times[i][k] != 100000000001 and times[k][j] != 100000000001:
                times[i][j] = min(times[i][j], times[i][k] + times[k][j]) times[i][k] != 100000000001 and times[k][j] != 100000000001 times[i][k] != 100000000001 times[i][k] [i] times i k 100000000001 times[k][j] != 100000000001 times[k][j] [k] times k j 100000000001 times[i][j] = min(times[i][j], times[i][k] + times[k][j]) times[i][j] [i] times i j min(times[i][j], times[i][k] + times[k][j]) min times[i][j] [i] times i j times[i][k] + times[k][j] times[i][k] [i] times i k times[k][j] [k] times k j Q=int(input()) Q int(input()) int input() input for i in range(Q):
    s,t=map(int,input().split())
    if times[s-1][t-1]!=100000000001:
    	print(times[s-1][t-1]-1)
    else:
      	print(-1) i range(Q) range Q s,t=map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t if times[s-1][t-1]!=100000000001:
    	print(times[s-1][t-1]-1)
    else:
      	print(-1) times[s-1][t-1]!=100000000001 times[s-1][t-1] [s-1] times s-1 s 1 t-1 t 1 100000000001 print(times[s-1][t-1]-1) print times[s-1][t-1]-1 times[s-1][t-1] [s-1] times s-1 s 1 t-1 t 1 1 print(-1) print -1 B=[[] for i in range(N)] [[] for i in range(N)] B c=map(int,input().split()) map(int,input().split()) c Q=int(input()) int(input()) Q A=[[] for i in range(N)] [[] for i in range(N)] A b,c=map(int,input().split()) map(int,input().split()) b times=[[100000000001]*N for i in range(N)] [[100000000001]*N for i in range(N)] times N,M,L=map(int,input().split()) map(int,input().split()) N d=[[100000000001]*N for i in range(N)] [[100000000001]*N for i in range(N)] d M,L=map(int,input().split()) map(int,input().split()) M L=map(int,input().split()) map(int,input().split()) L t=map(int,input().split()) map(int,input().split()) t a,b,c=map(int,input().split()) map(int,input().split()) a s,t=map(int,input().split()) map(int,input().split()) s
N,M,L=map(int,input().split())
A=[[] for i in range(N)]
for i in range(M):
    a,b,c=map(int,input().split())
    A[a-1].append((b-1,c))
    A[b-1].append((a-1,c))
d=[[100000000001]*N for i in range(N)]
for i in range(N):
    d[i][i]=0
for i in range(N):
    for to,cost in A[i]:
        d[i][to] = cost
for k in range(N):
    for i in range(N):
        for j in range(N):
            if d[i][k] != 100000000001 and d[k][j] != 100000000001:
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
B=[[] for i in range(N)]
for i in range(N):
    for j in range(N):
        if d[i][j]<=L:
            B[i].append((j,1))
times=[[100000000001]*N for i in range(N)]
for i in range(N):
    times[i][i]=0
for i in range(N):
    for to,cost in B[i]:
        times[i][to] = cost
for k in range(N):
    for i in range(N):
        for j in range(N):
            if times[i][k] != 100000000001 and times[k][j] != 100000000001:
                times[i][j] = min(times[i][j], times[i][k] + times[k][j])
Q=int(input())
for i in range(Q):
    s,t=map(int,input().split())
    if times[s-1][t-1]!=100000000001:
    	print(times[s-1][t-1]-1)
    else:
      	print(-1)