import sys
input = sys.stdin.readline
 
n, m, l = map(int, input().split())
 
INF = float("INF")
 
d = [[INF] * n for _ in range(n)]
for i in range(n):
    d[i][i] = 0
 
for i in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c
 
for k in range(n):
    for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
 
# print()
# print(*d, sep='\n')
 
for i in range(n):
    for j in range(n):
        if i == j:
            continue
 
        if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = INF
 
for k in range(n):
    for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
 
# print()
# print(*d, sep='\n')
 
q = int(input())
for i in range(q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
 
    if d[s][t] == INF:
        print(-1)
    else:
        print(d[s][t]-1) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline 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" [INF] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [INF] * n [INF] INF n d = [[INF] * n for _ in range(n)] d [[INF] * n for _ 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(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    d[a][b] = c
    d[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 d[a][b] = c d[a][b] [a] d a b c d[b][a] = c d[b][a] [b] d b a c for k in range(n):
    for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
 
# print()
# print(*d, sep='\n')
  k range(n) range n for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
 
# print()
# print(*d, sep='\n')
  i range(n) range n for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
 
# print()
# print(*d, sep='\n')
  j range(n) range n if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
 
# print()
# print(*d, sep='\n')
  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[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 for i in range(n):
    for j in range(n):
        if i == j:
            continue
 
        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 i == j:
            continue
 
        if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = INF
  j range(n) range n if i == j:
            continue
 
         i == j i j continue 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 k in range(n):
    for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
 
# print()
# print(*d, sep='\n')
  k range(n) range n for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
 
# print()
# print(*d, sep='\n')
  i range(n) range n for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
 
# print()
# print(*d, sep='\n')
  j range(n) range n if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
 
# print()
# print(*d, sep='\n')
  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[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 q = int(input()) q int(input()) int input() input for i in range(q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
 
    if d[s][t] == INF:
        print(-1)
    else:
        print(d[s][t]-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 s -= 1 s 1 t -= 1 t 1 if d[s][t] == INF:
        print(-1)
    else:
        print(d[s][t]-1) d[s][t] == INF d[s][t] [s] d s t INF print(-1) print -1 print(d[s][t]-1) print d[s][t]-1 d[s][t] [s] d s t 1 t = map(int, input().split()) map(int, input().split()) t s, t = map(int, input().split()) map(int, input().split()) s a, b, c = map(int, input().split()) map(int, input().split()) a m, l = map(int, input().split()) map(int, input().split()) m INF = float("INF") float("INF") INF s -= 1 1 s a -= 1 1 a l = map(int, input().split()) map(int, input().split()) l c = map(int, input().split()) map(int, input().split()) c q = int(input()) int(input()) q n, m, l = map(int, input().split()) map(int, input().split()) n b, c = map(int, input().split()) map(int, input().split()) b input = sys.stdin.readline sys.stdin.readline input t -= 1 1 t d = [[INF] * n for _ in range(n)] [[INF] * n for _ in range(n)] d b -= 1 1 b
import sys
input = sys.stdin.readline
 
n, m, l = map(int, input().split())
 
INF = float("INF")
 
d = [[INF] * n for _ in range(n)]
for i in range(n):
    d[i][i] = 0
 
for i in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c
 
for k in range(n):
    for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
 
# print()
# print(*d, sep='\n')
 
for i in range(n):
    for j in range(n):
        if i == j:
            continue
 
        if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = INF
 
for k in range(n):
    for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
 
# print()
# print(*d, sep='\n')
 
q = int(input())
for i in range(q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
 
    if d[s][t] == INF:
        print(-1)
    else:
        print(d[s][t]-1)