import sys
input = sys.stdin.readline
N, M, L = map(int, input().split())
INF = float('inf')
VD = [[INF] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    VD[a][b] = c
    VD[b][a] = c
for i in range(N):
    VD[i][i] = 0
 
for k in range(N):
    for i in range(N):
        for j in range(N):
            if VD[i][j] > VD[i][k] + VD[k][j]:
                VD[i][j] = VD[i][k] + VD[k][j]
 
WD = [[INF] * N for _ in range(N)]
for i in range(N):
    WD[i][i] = 0
    for j in range(i+1,N):
        d = VD[i][j]
        if d <= L:
            WD[i][j] = 1
            WD[j][i] = 1
 
for k in range(N):
    for i in range(N):
        for j in range(N):
            if WD[i][j] > WD[i][k] + WD[k][j]:
                WD[i][j] = WD[i][k] + WD[k][j]
 
Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    print(WD[s-1][t-1]-1 if WD[s-1][t-1] < INF else -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 VD = [[INF] * N for _ in range(N)] VD [[INF] * N for _ in range(N)] for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    VD[a][b] = c
    VD[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 VD[a][b] = c VD[a][b] [a] VD a b c VD[b][a] = c VD[b][a] [b] VD b a c for i in range(N):
    VD[i][i] = 0
  i range(N) range N VD[i][i] = 0 VD[i][i] [i] VD i i 0 for k in range(N):
    for i in range(N):
        for j in range(N):
            if VD[i][j] > VD[i][k] + VD[k][j]:
                VD[i][j] = VD[i][k] + VD[k][j]
  k range(N) range N for i in range(N):
        for j in range(N):
            if VD[i][j] > VD[i][k] + VD[k][j]:
                VD[i][j] = VD[i][k] + VD[k][j]
  i range(N) range N for j in range(N):
            if VD[i][j] > VD[i][k] + VD[k][j]:
                VD[i][j] = VD[i][k] + VD[k][j]
  j range(N) range N if VD[i][j] > VD[i][k] + VD[k][j]:
                VD[i][j] = VD[i][k] + VD[k][j]
  VD[i][j] > VD[i][k] + VD[k][j] VD[i][j] [i] VD i j VD[i][k] + VD[k][j] VD[i][k] [i] VD i k VD[k][j] [k] VD k j VD[i][j] = VD[i][k] + VD[k][j] VD[i][j] [i] VD i j VD[i][k] + VD[k][j] VD[i][k] [i] VD i k VD[k][j] [k] VD 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 WD = [[INF] * N for _ in range(N)] WD [[INF] * N for _ in range(N)] for i in range(N):
    WD[i][i] = 0
    for j in range(i+1,N):
        d = VD[i][j]
        if d <= L:
            WD[i][j] = 1
            WD[j][i] = 1
  i range(N) range N WD[i][i] = 0 WD[i][i] [i] WD i i 0 for j in range(i+1,N):
        d = VD[i][j]
        if d <= L:
            WD[i][j] = 1
            WD[j][i] = 1
  j range(i+1,N) range i+1 i 1 N d = VD[i][j] d VD[i][j] [i] VD i j if d <= L:
            WD[i][j] = 1
            WD[j][i] = 1
  d <= L d L WD[i][j] = 1 WD[i][j] [i] WD i j 1 WD[j][i] = 1 WD[j][i] [j] WD j i 1 for k in range(N):
    for i in range(N):
        for j in range(N):
            if WD[i][j] > WD[i][k] + WD[k][j]:
                WD[i][j] = WD[i][k] + WD[k][j]
  k range(N) range N for i in range(N):
        for j in range(N):
            if WD[i][j] > WD[i][k] + WD[k][j]:
                WD[i][j] = WD[i][k] + WD[k][j]
  i range(N) range N for j in range(N):
            if WD[i][j] > WD[i][k] + WD[k][j]:
                WD[i][j] = WD[i][k] + WD[k][j]
  j range(N) range N if WD[i][j] > WD[i][k] + WD[k][j]:
                WD[i][j] = WD[i][k] + WD[k][j]
  WD[i][j] > WD[i][k] + WD[k][j] WD[i][j] [i] WD i j WD[i][k] + WD[k][j] WD[i][k] [i] WD i k WD[k][j] [k] WD k j WD[i][j] = WD[i][k] + WD[k][j] WD[i][j] [i] WD i j WD[i][k] + WD[k][j] WD[i][k] [i] WD i k WD[k][j] [k] WD k j Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s, t = map(int, input().split())
    print(WD[s-1][t-1]-1 if WD[s-1][t-1] < INF else -1) _ range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t print(WD[s-1][t-1]-1 if WD[s-1][t-1] < INF else -1) print WD[s-1][t-1]-1 if WD[s-1][t-1] < INF else -1 WD[s-1][t-1] < INF WD[s-1][t-1] [s-1] WD s-1 s 1 t-1 t 1 INF WD[s-1][t-1]-1 WD[s-1][t-1] [s-1] WD s-1 s 1 t-1 t 1 1 -1 input = sys.stdin.readline sys.stdin.readline input s, t = map(int, input().split()) map(int, input().split()) s M, L = map(int, input().split()) map(int, input().split()) M a -= 1 1 a a, b, c = map(int, input().split()) map(int, input().split()) a WD = [[INF] * N for _ in range(N)] [[INF] * N for _ in range(N)] WD b, c = map(int, input().split()) map(int, input().split()) b b -= 1 1 b L = map(int, input().split()) map(int, input().split()) L t = map(int, input().split()) map(int, input().split()) t VD = [[INF] * N for _ in range(N)] [[INF] * N for _ in range(N)] VD INF = float('inf') float('inf') INF Q = int(input()) int(input()) Q d = VD[i][j] VD[i][j] d c = map(int, input().split()) map(int, input().split()) c N, M, L = map(int, input().split()) map(int, input().split()) N
import sys
input = sys.stdin.readline
N, M, L = map(int, input().split())
INF = float('inf')
VD = [[INF] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    VD[a][b] = c
    VD[b][a] = c
for i in range(N):
    VD[i][i] = 0
 
for k in range(N):
    for i in range(N):
        for j in range(N):
            if VD[i][j] > VD[i][k] + VD[k][j]:
                VD[i][j] = VD[i][k] + VD[k][j]
 
WD = [[INF] * N for _ in range(N)]
for i in range(N):
    WD[i][i] = 0
    for j in range(i+1,N):
        d = VD[i][j]
        if d <= L:
            WD[i][j] = 1
            WD[j][i] = 1
 
for k in range(N):
    for i in range(N):
        for j in range(N):
            if WD[i][j] > WD[i][k] + WD[k][j]:
                WD[i][j] = WD[i][k] + WD[k][j]
 
Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    print(WD[s-1][t-1]-1 if WD[s-1][t-1] < INF else -1)