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

INF = 1 << 30
g = [[INF] * n for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    g[a][b] = c
    g[b][a] = c

for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j] = min(g[i][j], g[i][k] + g[k][j])

h = [[INF] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if g[i][j] <= l:
            h[i][j] = 1

for k in range(n):
    for i in range(n):
        for j in range(n):
            h[i][j] = min(h[i][j], h[i][k] + h[k][j])

q = int(input())
for _ in range(q):
    s, t = map(lambda x: int(x) - 1, input().split())
    if h[s][t] == INF:
        print(-1)
    else:
        print(h[s][t] - 1) n, m, l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l INF = 1 << 30 INF 1 << 30 1 30 [INF] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [INF] * n [INF] INF n g = [[INF] * n for _ in range(n)] g [[INF] * n for _ in range(n)] for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    g[a][b] = c
    g[b][a] = 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 a -= 1 a 1 b -= 1 b 1 g[a][b] = c g[a][b] [a] g a b c g[b][a] = c g[b][a] [b] g b a c for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j] = min(g[i][j], g[i][k] + g[k][j]) k range(n) range n for i in range(n):
        for j in range(n):
            g[i][j] = min(g[i][j], g[i][k] + g[k][j]) i range(n) range n for j in range(n):
            g[i][j] = min(g[i][j], g[i][k] + g[k][j]) j range(n) range n g[i][j] = min(g[i][j], g[i][k] + g[k][j]) g[i][j] [i] g i j min(g[i][j], g[i][k] + g[k][j]) min g[i][j] [i] g i j g[i][k] + g[k][j] g[i][k] [i] g i k g[k][j] [k] g k j [INF] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [INF] * n [INF] INF n h = [[INF] * n for _ in range(n)] h [[INF] * n for _ in range(n)] for i in range(n):
    for j in range(n):
        if g[i][j] <= l:
            h[i][j] = 1 i range(n) range n for j in range(n):
        if g[i][j] <= l:
            h[i][j] = 1 j range(n) range n if g[i][j] <= l:
            h[i][j] = 1 g[i][j] <= l g[i][j] [i] g i j l h[i][j] = 1 h[i][j] [i] h i j 1 for k in range(n):
    for i in range(n):
        for j in range(n):
            h[i][j] = min(h[i][j], h[i][k] + h[k][j]) k range(n) range n for i in range(n):
        for j in range(n):
            h[i][j] = min(h[i][j], h[i][k] + h[k][j]) i range(n) range n for j in range(n):
            h[i][j] = min(h[i][j], h[i][k] + h[k][j]) j range(n) range n h[i][j] = min(h[i][j], h[i][k] + h[k][j]) h[i][j] [i] h i j min(h[i][j], h[i][k] + h[k][j]) min h[i][j] [i] h i j h[i][k] + h[k][j] h[i][k] [i] h i k h[k][j] [k] h k j q = int(input()) q int(input()) int input() input for _ in range(q):
    s, t = map(lambda x: int(x) - 1, input().split())
    if h[s][t] == INF:
        print(-1)
    else:
        print(h[s][t] - 1) _ range(q) range q s, t = map(lambda x: int(x) - 1, input().split()) s map(lambda x: int(x) - 1, input().split()) map lambda x: int(x) - 1 int(x) - 1 int(x) int x 1 x input().split() ().split () input split t if h[s][t] == INF:
        print(-1)
    else:
        print(h[s][t] - 1) h[s][t] == INF h[s][t] [s] h s t INF print(-1) print -1 print(h[s][t] - 1) print h[s][t] - 1 h[s][t] [s] h s t 1 g = [[INF] * n for _ in range(n)] [[INF] * n for _ in range(n)] g b -= 1 1 b n, m, l = map(int, input().split()) map(int, input().split()) n s, t = map(lambda x: int(x) - 1, input().split()) map(lambda x: int(x) - 1, input().split()) s a, b, c = map(int, input().split()) map(int, input().split()) a b, c = map(int, input().split()) map(int, input().split()) b m, l = map(int, input().split()) map(int, input().split()) m t = map(lambda x: int(x) - 1, input().split()) map(lambda x: int(x) - 1, input().split()) t a -= 1 1 a l = map(int, input().split()) map(int, input().split()) l c = map(int, input().split()) map(int, input().split()) c h = [[INF] * n for _ in range(n)] [[INF] * n for _ in range(n)] h INF = 1 << 30 1 << 30 INF q = int(input()) int(input()) q
n, m, l = map(int, input().split())

INF = 1 << 30
g = [[INF] * n for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    g[a][b] = c
    g[b][a] = c

for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j] = min(g[i][j], g[i][k] + g[k][j])

h = [[INF] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if g[i][j] <= l:
            h[i][j] = 1

for k in range(n):
    for i in range(n):
        for j in range(n):
            h[i][j] = min(h[i][j], h[i][k] + h[k][j])

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