N,M,L = map(int,input().split())
INF = 10**18
d = [[INF for j in range(N)] for i in range(N)]

# 入力
for _ in range(M):
    A,B,C = map(int,input().split())
    if L < C:
        continue
    d[A-1][B-1] = C
    d[B-1][A-1] = C

# 初期化
for i in range(N):
    d[i][i] = 0

# ワーシャルフロイド1回目
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 d[i][j] <= L:
            d[i][j] = 1
        else:
            d[i][j] = INF

# 初期化
for i in range(N):
    d[i][i] = 0

# ワーシャルフロイド2回目
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])

Q = int(input())

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

# ワーシャルフロイド1回目 i range(N) range N d[i][i] = 0 d[i][i] [i] d i i 0 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 d[i][j] <= L:
            d[i][j] = 1
        else:
            d[i][j] = INF

# 初期化 i range(N) range N for j in range(N):
        if d[i][j] <= L:
            d[i][j] = 1
        else:
            d[i][j] = INF

# 初期化 j range(N) range N if d[i][j] <= L:
            d[i][j] = 1
        else:
            d[i][j] = INF

# 初期化 d[i][j] <= L d[i][j] [i] d i j L d[i][j] = 1 d[i][j] [i] d i j 1 d[i][j] = INF d[i][j] [i] d i j INF for i in range(N):
    d[i][i] = 0

# ワーシャルフロイド2回目 i range(N) range N d[i][i] = 0 d[i][i] [i] d i i 0 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 Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s,t = map(int,input().split())
    if d[s-1][t-1] == INF:
        print(-1)
    else:
        print(d[s-1][t-1]-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 d[s-1][t-1] == INF:
        print(-1)
    else:
        print(d[s-1][t-1]-1) d[s-1][t-1] == INF d[s-1][t-1] [s-1] d s-1 s 1 t-1 t 1 INF print(-1) print -1 print(d[s-1][t-1]-1) print d[s-1][t-1]-1 d[s-1][t-1] [s-1] d s-1 s 1 t-1 t 1 1 t = map(int,input().split()) map(int,input().split()) t M,L = map(int,input().split()) map(int,input().split()) M d = [[INF for j in range(N)] for i in range(N)] [[INF for j in range(N)] for i in range(N)] d INF = 10**18 10**18 INF B,C = map(int,input().split()) map(int,input().split()) B N,M,L = map(int,input().split()) map(int,input().split()) N s,t = map(int,input().split()) map(int,input().split()) s C = map(int,input().split()) map(int,input().split()) C A,B,C = map(int,input().split()) map(int,input().split()) A L = map(int,input().split()) map(int,input().split()) L Q = int(input()) int(input()) Q
N,M,L = map(int,input().split())
INF = 10**18
d = [[INF for j in range(N)] for i in range(N)]

# 入力
for _ in range(M):
    A,B,C = map(int,input().split())
    if L < C:
        continue
    d[A-1][B-1] = C
    d[B-1][A-1] = C

# 初期化
for i in range(N):
    d[i][i] = 0

# ワーシャルフロイド1回目
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 d[i][j] <= L:
            d[i][j] = 1
        else:
            d[i][j] = INF

# 初期化
for i in range(N):
    d[i][i] = 0

# ワーシャルフロイド2回目
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])

Q = int(input())

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

