N, M, L= map(int,input().split())
cost = [[float('inf')]*N for i in range(N)]

for i in range(N):
    cost[i][i] = 0

for _ in range(M):
    a,b,c = map(int,input().split())
    cost[a-1][b-1] = c
    cost[b-1][a-1] = c
def func(f):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                f[i][j] = min(f[i][k] + f[k][j], f[i][j])
    return f
cost = func(cost)
for i in range(N):
    for j in range(N):
        if cost[i][j] > L:
            cost[i][j] = float('inf')
        else:
            cost[i][j] = 1
cost = func(cost)

Q = int(input())
ans = []
for i in range(Q):
    s,t = map(int,input().split())
    ans.append(cost[s-1][t-1]-1)
for i in ans:
    if i == float('inf'):
        print(-1)
    else:
        print(i) N, M, L= map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L [float('inf')]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [float('inf')]*N [float('inf')] float('inf') float 'inf' N cost = [[float('inf')]*N for i in range(N)] cost [[float('inf')]*N for i in range(N)] for i in range(N):
    cost[i][i] = 0 i range(N) range N cost[i][i] = 0 cost[i][i] [i] cost i i 0 for _ in range(M):
    a,b,c = map(int,input().split())
    cost[a-1][b-1] = c
    cost[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 cost[a-1][b-1] = c cost[a-1][b-1] [a-1] cost a-1 a 1 b-1 b 1 c cost[b-1][a-1] = c cost[b-1][a-1] [b-1] cost b-1 b 1 a-1 a 1 c def func(f):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                f[i][j] = min(f[i][k] + f[k][j], f[i][j])
    return f func for k in range(N):
        for i in range(N):
            for j in range(N):
                f[i][j] = min(f[i][k] + f[k][j], f[i][j])
     k range(N) range N for i in range(N):
            for j in range(N):
                f[i][j] = min(f[i][k] + f[k][j], f[i][j])
     i range(N) range N for j in range(N):
                f[i][j] = min(f[i][k] + f[k][j], f[i][j])
     j range(N) range N f[i][j] = min(f[i][k] + f[k][j], f[i][j]) f[i][j] [i] f i j min(f[i][k] + f[k][j], f[i][j]) min f[i][k] + f[k][j] f[i][k] [i] f i k f[k][j] [k] f k j f[i][j] [i] f i j return f f f f cost = func(cost) cost func(cost) func cost for i in range(N):
    for j in range(N):
        if cost[i][j] > L:
            cost[i][j] = float('inf')
        else:
            cost[i][j] = 1 i range(N) range N for j in range(N):
        if cost[i][j] > L:
            cost[i][j] = float('inf')
        else:
            cost[i][j] = 1 j range(N) range N if cost[i][j] > L:
            cost[i][j] = float('inf')
        else:
            cost[i][j] = 1 cost[i][j] > L cost[i][j] [i] cost i j L cost[i][j] = float('inf') cost[i][j] [i] cost i j float('inf') float 'inf' cost[i][j] = 1 cost[i][j] [i] cost i j 1 cost = func(cost) cost func(cost) func cost Q = int(input()) Q int(input()) int input() input ans = [] ans [] for i in range(Q):
    s,t = map(int,input().split())
    ans.append(cost[s-1][t-1]-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 ans.append(cost[s-1][t-1]-1) ans.append ans append cost[s-1][t-1]-1 cost[s-1][t-1] [s-1] cost s-1 s 1 t-1 t 1 1 for i in ans:
    if i == float('inf'):
        print(-1)
    else:
        print(i) i ans if i == float('inf'):
        print(-1)
    else:
        print(i) i == float('inf') i float('inf') float 'inf' print(-1) print -1 print(i) print i cost = [[float('inf')]*N for i in range(N)] [[float('inf')]*N for i in range(N)] cost M, L= map(int,input().split()) map(int,input().split()) M def func(f):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                f[i][j] = min(f[i][k] + f[k][j], f[i][j])
    return f def func(f):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                f[i][j] = min(f[i][k] + f[k][j], f[i][j])
    return f func cost = func(cost) func(cost) cost N, M, L= map(int,input().split()) map(int,input().split()) N s,t = map(int,input().split()) map(int,input().split()) s t = map(int,input().split()) map(int,input().split()) t L= map(int,input().split()) map(int,input().split()) L a,b,c = map(int,input().split()) map(int,input().split()) a b,c = map(int,input().split()) map(int,input().split()) b Q = int(input()) int(input()) Q c = map(int,input().split()) map(int,input().split()) c ans = [] [] ans cost = func(cost) func(cost) cost
N, M, L= map(int,input().split())
cost = [[float('inf')]*N for i in range(N)]

for i in range(N):
    cost[i][i] = 0

for _ in range(M):
    a,b,c = map(int,input().split())
    cost[a-1][b-1] = c
    cost[b-1][a-1] = c
def func(f):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                f[i][j] = min(f[i][k] + f[k][j], f[i][j])
    return f
cost = func(cost)
for i in range(N):
    for j in range(N):
        if cost[i][j] > L:
            cost[i][j] = float('inf')
        else:
            cost[i][j] = 1
cost = func(cost)

Q = int(input())
ans = []
for i in range(Q):
    s,t = map(int,input().split())
    ans.append(cost[s-1][t-1]-1)
for i in ans:
    if i == float('inf'):
        print(-1)
    else:
        print(i)
