from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m,l = inpl()
d = [[INF]*n for _ in range(n)]
for _ in range(m):
    a,b,c = inpl()
    d[a-1][b-1] = c
    d[b-1][a-1] = c
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[k][j])
e = [[INF]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if d[i][j] <= l:
            e[i][j] = 1

for k in range(n):
    for i in range(n):
        for j in range(n):
            e[i][j] = min(e[i][j], e[i][k]+e[k][j])
q = inp()
for _ in range(q):
    a,b = inpl()
    ans = e[a-1][b-1]
    print(-1 if ans == INF else ans-1) from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions sys bisect math itertools fractions sys.setrecursionlimit(10**8) sys.setrecursionlimit sys setrecursionlimit 10**8 10 8 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 INF = float('inf') INF float('inf') float 'inf' def inp(): return int(sys.stdin.readline()) inp def inpl(): return list(map(int, sys.stdin.readline().split())) inpl n,m,l = inpl() n inpl() inpl m l [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 _ in range(m):
    a,b,c = inpl()
    d[a-1][b-1] = c
    d[b-1][a-1] = c _ range(m) range m a,b,c = inpl() a inpl() inpl 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 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[k][j]) 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[k][j]) i range(n) range n for j in range(n):
            d[i][j] = min(d[i][j], d[i][k]+d[k][j]) j range(n) range n d[i][j] = min(d[i][j], d[i][k]+d[k][j]) d[i][j] [i] d i j min(d[i][j], d[i][k]+d[k][j]) min 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 [INF]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [INF]*n [INF] INF n e = [[INF]*n for _ in range(n)] e [[INF]*n for _ in range(n)] for i in range(n):
    for j in range(n):
        if d[i][j] <= l:
            e[i][j] = 1 i range(n) range n for j in range(n):
        if d[i][j] <= l:
            e[i][j] = 1 j range(n) range n if d[i][j] <= l:
            e[i][j] = 1 d[i][j] <= l d[i][j] [i] d i j l e[i][j] = 1 e[i][j] [i] e i j 1 for k in range(n):
    for i in range(n):
        for j in range(n):
            e[i][j] = min(e[i][j], e[i][k]+e[k][j]) k range(n) range n for i in range(n):
        for j in range(n):
            e[i][j] = min(e[i][j], e[i][k]+e[k][j]) i range(n) range n for j in range(n):
            e[i][j] = min(e[i][j], e[i][k]+e[k][j]) j range(n) range n e[i][j] = min(e[i][j], e[i][k]+e[k][j]) e[i][j] [i] e i j min(e[i][j], e[i][k]+e[k][j]) min e[i][j] [i] e i j e[i][k]+e[k][j] e[i][k] [i] e i k e[k][j] [k] e k j q = inp() q inp() inp for _ in range(q):
    a,b = inpl()
    ans = e[a-1][b-1]
    print(-1 if ans == INF else ans-1) _ range(q) range q a,b = inpl() a inpl() inpl b ans = e[a-1][b-1] ans e[a-1][b-1] [a-1] e a-1 a 1 b-1 b 1 print(-1 if ans == INF else ans-1) print -1 if ans == INF else ans-1 ans == INF ans INF -1 ans-1 ans 1 a,b = inpl() inpl() a mod = 10**9+7 10**9+7 mod q = inp() inp() q def inp(): return int(sys.stdin.readline()) def inp(): return int(sys.stdin.readline()) inp b,c = inpl() inpl() b b = inpl() inpl() b m,l = inpl() inpl() m d = [[INF]*n for _ in range(n)] [[INF]*n for _ in range(n)] d e = [[INF]*n for _ in range(n)] [[INF]*n for _ in range(n)] e c = inpl() inpl() c INF = float('inf') float('inf') INF n,m,l = inpl() inpl() n l = inpl() inpl() l def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl(): return list(map(int, sys.stdin.readline().split())) inpl a,b,c = inpl() inpl() a ans = e[a-1][b-1] e[a-1][b-1] ans
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m,l = inpl()
d = [[INF]*n for _ in range(n)]
for _ in range(m):
    a,b,c = inpl()
    d[a-1][b-1] = c
    d[b-1][a-1] = c
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[k][j])
e = [[INF]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if d[i][j] <= l:
            e[i][j] = 1

for k in range(n):
    for i in range(n):
        for j in range(n):
            e[i][j] = min(e[i][j], e[i][k]+e[k][j])
q = inp()
for _ in range(q):
    a,b = inpl()
    ans = e[a-1][b-1]
    print(-1 if ans == INF else ans-1)
