from scipy.sparse.csgraph import dijkstra as di

n,m,l = map(int, input().split())

inf = float('INF')
road = [[0 for i in range(n)] for j in range(n)]
for i in range(m):
    a,b,c = map(int, input().split())
    a -= 1
    b -= 1
    road[a][b] = road[b][a] = c

def warshall(d, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][k] + d[k][j] < d[i][j]:
                    d[i][j] = d[i][k] + d[k][j]

roads = di(road, n)
# [print(cost) for cost in road]
# print()
costs = [[1 if roads[i][j] <= l and i != j else 0 for j in range(n)] for i in range(n)]
costs = di(costs, n)

# [print(cost) for cost in costs]
q = int(input())
for i in range(q):
    s,t = map(int, input().split())
    
    print(int(costs[s-1][t-1]-1) if costs[s-1][t-1] < inf else -1) from scipy.sparse.csgraph import dijkstra as di n,m,l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l inf = float('INF') inf float('INF') float 'INF' [0 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) [0 for i in range(n)] road = [[0 for i in range(n)] for j in range(n)] road [[0 for i in range(n)] for j in range(n)] for i in range(m):
    a,b,c = map(int, input().split())
    a -= 1
    b -= 1
    road[a][b] = road[b][a] = 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 -= 1 a 1 b -= 1 b 1 road[a][b] = road[b][a] = c road[a][b] [a] road a b c = road[b][a] = c road[b][a] [b] road b a c def warshall(d, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][k] + d[k][j] < d[i][j]:
                    d[i][j] = d[i][k] + d[k][j] warshall for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][k] + d[k][j] < d[i][j]:
                    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] + d[k][j] < d[i][j]:
                    d[i][j] = d[i][k] + d[k][j] i range(n) range n for j in range(n):
                if d[i][k] + d[k][j] < d[i][j]:
                    d[i][j] = d[i][k] + d[k][j] j range(n) range n if d[i][k] + d[k][j] < d[i][j]:
                    d[i][j] = d[i][k] + d[k][j] d[i][k] + d[k][j] < d[i][j] d[i][k] + d[k][j] d[i][k] [i] d i k d[k][j] [k] d k j d[i][j] [i] d i j d[i][j] = d[i][k] + d[k][j] 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 d d n n roads = di(road, n) roads di(road, n) di road n [1 if roads[i][j] <= l and i != j else 0 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) [1 if roads[i][j] <= l and i != j else 0 for j in range(n)] costs = [[1 if roads[i][j] <= l and i != j else 0 for j in range(n)] for i in range(n)] costs [[1 if roads[i][j] <= l and i != j else 0 for j in range(n)] for i in range(n)] costs = di(costs, n) costs di(costs, n) di costs n q = int(input()) q int(input()) int input() input for i in range(q):
    s,t = map(int, input().split())
    
    print(int(costs[s-1][t-1]-1) if costs[s-1][t-1] < inf else -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 print(int(costs[s-1][t-1]-1) if costs[s-1][t-1] < inf else -1) print int(costs[s-1][t-1]-1) if costs[s-1][t-1] < inf else -1 costs[s-1][t-1] < inf costs[s-1][t-1] [s-1] costs s-1 s 1 t-1 t 1 inf int(costs[s-1][t-1]-1) int costs[s-1][t-1]-1 costs[s-1][t-1] [s-1] costs s-1 s 1 t-1 t 1 1 -1 costs = [[1 if roads[i][j] <= l and i != j else 0 for j in range(n)] for i in range(n)] [[1 if roads[i][j] <= l and i != j else 0 for j in range(n)] for i in range(n)] costs road = [[0 for i in range(n)] for j in range(n)] [[0 for i in range(n)] for j in range(n)] road a -= 1 1 a q = int(input()) int(input()) q l = map(int, input().split()) map(int, input().split()) l inf = float('INF') float('INF') inf costs = di(costs, n) di(costs, n) costs m,l = map(int, input().split()) map(int, input().split()) m b,c = map(int, input().split()) map(int, input().split()) b b -= 1 1 b s,t = map(int, input().split()) map(int, input().split()) s def warshall(d, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][k] + d[k][j] < d[i][j]:
                    d[i][j] = d[i][k] + d[k][j] def warshall(d, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][k] + d[k][j] < d[i][j]:
                    d[i][j] = d[i][k] + d[k][j] warshall t = map(int, input().split()) map(int, input().split()) t n,m,l = map(int, input().split()) map(int, input().split()) n a,b,c = map(int, input().split()) map(int, input().split()) a roads = di(road, n) di(road, n) roads c = map(int, input().split()) map(int, input().split()) c
from scipy.sparse.csgraph import dijkstra as di

n,m,l = map(int, input().split())

inf = float('INF')
road = [[0 for i in range(n)] for j in range(n)]
for i in range(m):
    a,b,c = map(int, input().split())
    a -= 1
    b -= 1
    road[a][b] = road[b][a] = c

def warshall(d, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][k] + d[k][j] < d[i][j]:
                    d[i][j] = d[i][k] + d[k][j]

roads = di(road, n)
# [print(cost) for cost in road]
# print()
costs = [[1 if roads[i][j] <= l and i != j else 0 for j in range(n)] for i in range(n)]
costs = di(costs, n)

# [print(cost) for cost in costs]
q = int(input())
for i in range(q):
    s,t = map(int, input().split())
    
    print(int(costs[s-1][t-1]-1) if costs[s-1][t-1] < inf else -1)
