from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

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

    return d

N, M, L = list(map(int, input().split()))

d = [[INF for j in range(N)] for i in range(N)]
for i in range(M):
    a, b, c = map(int,input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c

d = warshall_floyd(d, N)

dd = [[INF for j in range(N)] for i in range(N)]
for i in range(N):
    for j in range(i+1, N):
        if d[i][j] <= L:
            dd[i][j] = 1
            dd[j][i] = 1

dd = warshall_floyd(dd, N)

Q = int(input())
for q in range(Q):
    s, t = map(int, input().split())
    ans = dd[s-1][t-1]-1
    if ans == INF-1:
        print(-1)
    else:
        print(ans)
 from sys import stdin import sys sys import math math from functools import reduce import functools functools import itertools itertools from collections import deque,Counter,defaultdict from operator import mul import copy copy import heapq heapq sys.setrecursionlimit(10**6) sys.setrecursionlimit sys setrecursionlimit 10**6 10 6 INF = 10**18 INF 10**18 10 18 import bisect bisect import statistics statistics mod = 10**9+7 mod 10**9+7 10**9 10 9 7 def warshall_floyd(d,n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[j][k])

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

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

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

     j range(n) range n d[i][j] = min(d[i][j], d[i][k] + d[j][k]) d[i][j] [i] d i j min(d[i][j], d[i][k] + d[j][k]) min d[i][j] [i] d i j d[i][k] + d[j][k] d[i][k] [i] d i k d[j][k] [j] d j k return d d d d n n N, M, L = list(map(int, input().split())) N list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split M L [INF 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) [INF for j in range(N)] d = [[INF for j in range(N)] for i in range(N)] d [[INF for j in range(N)] for i in range(N)] for i in range(M):
    a, b, c = map(int,input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = 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 d[a-1][b-1] = c d[a-1][b-1] [a-1] d a-1 a 1 b-1 b 1 c d[b-1][a-1] = c d[b-1][a-1] [b-1] d b-1 b 1 a-1 a 1 c d = warshall_floyd(d, N) d warshall_floyd(d, N) warshall_floyd d N [INF 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) [INF for j in range(N)] dd = [[INF for j in range(N)] for i in range(N)] dd [[INF for j in range(N)] for i in range(N)] for i in range(N):
    for j in range(i+1, N):
        if d[i][j] <= L:
            dd[i][j] = 1
            dd[j][i] = 1 i range(N) range N for j in range(i+1, N):
        if d[i][j] <= L:
            dd[i][j] = 1
            dd[j][i] = 1 j range(i+1, N) range i+1 i 1 N if d[i][j] <= L:
            dd[i][j] = 1
            dd[j][i] = 1 d[i][j] <= L d[i][j] [i] d i j L dd[i][j] = 1 dd[i][j] [i] dd i j 1 dd[j][i] = 1 dd[j][i] [j] dd j i 1 dd = warshall_floyd(dd, N) dd warshall_floyd(dd, N) warshall_floyd dd N Q = int(input()) Q int(input()) int input() input for q in range(Q):
    s, t = map(int, input().split())
    ans = dd[s-1][t-1]-1
    if ans == INF-1:
        print(-1)
    else:
        print(ans) q range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t ans = dd[s-1][t-1]-1 ans dd[s-1][t-1]-1 dd[s-1][t-1] [s-1] dd s-1 s 1 t-1 t 1 1 if ans == INF-1:
        print(-1)
    else:
        print(ans) ans == INF-1 ans INF-1 INF 1 print(-1) print -1 print(ans) print ans mod = 10**9+7 10**9+7 mod a, b, c = map(int,input().split()) map(int,input().split()) a s, t = map(int, input().split()) map(int, input().split()) s N, M, L = list(map(int, input().split())) list(map(int, input().split())) N c = map(int,input().split()) map(int,input().split()) c ans = dd[s-1][t-1]-1 dd[s-1][t-1]-1 ans def warshall_floyd(d,n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[j][k])

    return d def warshall_floyd(d,n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[j][k])

    return d warshall_floyd b, c = map(int,input().split()) map(int,input().split()) b t = map(int, input().split()) map(int, input().split()) t d = [[INF for j in range(N)] for i in range(N)] [[INF for j in range(N)] for i in range(N)] d d = warshall_floyd(d, N) warshall_floyd(d, N) d dd = [[INF for j in range(N)] for i in range(N)] [[INF for j in range(N)] for i in range(N)] dd M, L = list(map(int, input().split())) list(map(int, input().split())) M INF = 10**18 10**18 INF dd = warshall_floyd(dd, N) warshall_floyd(dd, N) dd Q = int(input()) int(input()) Q L = list(map(int, input().split())) list(map(int, input().split())) L
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

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

    return d

N, M, L = list(map(int, input().split()))

d = [[INF for j in range(N)] for i in range(N)]
for i in range(M):
    a, b, c = map(int,input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c

d = warshall_floyd(d, N)

dd = [[INF for j in range(N)] for i in range(N)]
for i in range(N):
    for j in range(i+1, N):
        if d[i][j] <= L:
            dd[i][j] = 1
            dd[j][i] = 1

dd = warshall_floyd(dd, N)

Q = int(input())
for q in range(Q):
    s, t = map(int, input().split())
    ans = dd[s-1][t-1]-1
    if ans == INF-1:
        print(-1)
    else:
        print(ans)

