import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9323372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N,M,L=LI()

LG=10**15
DIST=[[LG for _ in range(N+1)] for _ in range(N+1)]
for i in range(M):
    a,b,c = LI()
    if c <= L:
        DIST[a][b] = c
        DIST[b][a] = c

for k in range(1, N+1):
    for i in range(1, N+1):
        for j in range(1, N+1):
            if DIST[i][j] > DIST[i][k] + DIST[k][j]:
                DIST[i][j] = DIST[i][k] + DIST[k][j]

for i in range(1, N+1):
    for j in range(1, N+1):
        DIST[i][j] = 1 if DIST[i][j] <= L else LG

for k in range(1, N+1):
    for i in range(1, N+1):
        for j in range(1, N+1):
            if DIST[i][j] > DIST[i][k] + DIST[k][j]:
                DIST[i][j] = DIST[i][k] + DIST[k][j]

for i in range(II()):
    st, en = LI()
    if DIST[st][en] >= LG:
        print(-1)
    else:
        print(DIST[st][en] - 1) import sys sys import math math import heapq heapq sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 INTMAX = 9323372036854775807 INTMAX 9323372036854775807 INTMIN = -9223372036854775808 INTMIN -9223372036854775808 DVSR = 1000000007 DVSR 1000000007 def POW(x, y): return pow(x, y, DVSR) POW x x y y def INV(x, m=DVSR): return pow(x, m - 2, m) INV x x m=DVSR m DVSR def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m DIV x x y y m=DVSR m DVSR int(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x) int x def LI(): return [int(x) for x in sys.stdin.readline().split()] LI float(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() float(x) float x def LF(): return [float(x) for x in sys.stdin.readline().split()] LF def LS(): return sys.stdin.readline().split() LS def II(): return int(sys.stdin.readline()) II def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res FLIST res = [1] res [1] 1 for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
     i range(1, n+1) range 1 n+1 n 1 return res res n n N,M,L=LI() N LI() LI M L LG=10**15 LG 10**15 10 15 [LG for _ in range(N+1)] for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [LG for _ in range(N+1)] DIST=[[LG for _ in range(N+1)] for _ in range(N+1)] DIST [[LG for _ in range(N+1)] for _ in range(N+1)] for i in range(M):
    a,b,c = LI()
    if c <= L:
        DIST[a][b] = c
        DIST[b][a] = c i range(M) range M a,b,c = LI() a LI() LI b c if c <= L:
        DIST[a][b] = c
        DIST[b][a] = c c <= L c L DIST[a][b] = c DIST[a][b] [a] DIST a b c DIST[b][a] = c DIST[b][a] [b] DIST b a c for k in range(1, N+1):
    for i in range(1, N+1):
        for j in range(1, N+1):
            if DIST[i][j] > DIST[i][k] + DIST[k][j]:
                DIST[i][j] = DIST[i][k] + DIST[k][j] k range(1, N+1) range 1 N+1 N 1 for i in range(1, N+1):
        for j in range(1, N+1):
            if DIST[i][j] > DIST[i][k] + DIST[k][j]:
                DIST[i][j] = DIST[i][k] + DIST[k][j] i range(1, N+1) range 1 N+1 N 1 for j in range(1, N+1):
            if DIST[i][j] > DIST[i][k] + DIST[k][j]:
                DIST[i][j] = DIST[i][k] + DIST[k][j] j range(1, N+1) range 1 N+1 N 1 if DIST[i][j] > DIST[i][k] + DIST[k][j]:
                DIST[i][j] = DIST[i][k] + DIST[k][j] DIST[i][j] > DIST[i][k] + DIST[k][j] DIST[i][j] [i] DIST i j DIST[i][k] + DIST[k][j] DIST[i][k] [i] DIST i k DIST[k][j] [k] DIST k j DIST[i][j] = DIST[i][k] + DIST[k][j] DIST[i][j] [i] DIST i j DIST[i][k] + DIST[k][j] DIST[i][k] [i] DIST i k DIST[k][j] [k] DIST k j for i in range(1, N+1):
    for j in range(1, N+1):
        DIST[i][j] = 1 if DIST[i][j] <= L else LG i range(1, N+1) range 1 N+1 N 1 for j in range(1, N+1):
        DIST[i][j] = 1 if DIST[i][j] <= L else LG j range(1, N+1) range 1 N+1 N 1 DIST[i][j] = 1 if DIST[i][j] <= L else LG DIST[i][j] [i] DIST i j 1 if DIST[i][j] <= L else LG DIST[i][j] <= L DIST[i][j] [i] DIST i j L 1 LG for k in range(1, N+1):
    for i in range(1, N+1):
        for j in range(1, N+1):
            if DIST[i][j] > DIST[i][k] + DIST[k][j]:
                DIST[i][j] = DIST[i][k] + DIST[k][j] k range(1, N+1) range 1 N+1 N 1 for i in range(1, N+1):
        for j in range(1, N+1):
            if DIST[i][j] > DIST[i][k] + DIST[k][j]:
                DIST[i][j] = DIST[i][k] + DIST[k][j] i range(1, N+1) range 1 N+1 N 1 for j in range(1, N+1):
            if DIST[i][j] > DIST[i][k] + DIST[k][j]:
                DIST[i][j] = DIST[i][k] + DIST[k][j] j range(1, N+1) range 1 N+1 N 1 if DIST[i][j] > DIST[i][k] + DIST[k][j]:
                DIST[i][j] = DIST[i][k] + DIST[k][j] DIST[i][j] > DIST[i][k] + DIST[k][j] DIST[i][j] [i] DIST i j DIST[i][k] + DIST[k][j] DIST[i][k] [i] DIST i k DIST[k][j] [k] DIST k j DIST[i][j] = DIST[i][k] + DIST[k][j] DIST[i][j] [i] DIST i j DIST[i][k] + DIST[k][j] DIST[i][k] [i] DIST i k DIST[k][j] [k] DIST k j for i in range(II()):
    st, en = LI()
    if DIST[st][en] >= LG:
        print(-1)
    else:
        print(DIST[st][en] - 1) i range(II()) range II() II st, en = LI() st LI() LI en if DIST[st][en] >= LG:
        print(-1)
    else:
        print(DIST[st][en] - 1) DIST[st][en] >= LG DIST[st][en] [st] DIST st en LG print(-1) print -1 print(DIST[st][en] - 1) print DIST[st][en] - 1 DIST[st][en] [st] DIST st en 1 st, en = LI() LI() st def POW(x, y): return pow(x, y, DVSR) def POW(x, y): return pow(x, y, DVSR) POW a,b,c = LI() LI() a M,L=LI() LI() M def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI(): return [int(x) for x in sys.stdin.readline().split()] LI L=LI() LI() L DIST=[[LG for _ in range(N+1)] for _ in range(N+1)] [[LG for _ in range(N+1)] for _ in range(N+1)] DIST INTMIN = -9223372036854775808 -9223372036854775808 INTMIN def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res FLIST b,c = LI() LI() b def LS(): return sys.stdin.readline().split() def LS(): return sys.stdin.readline().split() LS def INV(x, m=DVSR): return pow(x, m - 2, m) def INV(x, m=DVSR): return pow(x, m - 2, m) INV INTMAX = 9323372036854775807 9323372036854775807 INTMAX def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m DIV def II(): return int(sys.stdin.readline()) def II(): return int(sys.stdin.readline()) II c = LI() LI() c LG=10**15 10**15 LG en = LI() LI() en def LF(): return [float(x) for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] LF DVSR = 1000000007 1000000007 DVSR N,M,L=LI() LI() N
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9323372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N,M,L=LI()

LG=10**15
DIST=[[LG for _ in range(N+1)] for _ in range(N+1)]
for i in range(M):
    a,b,c = LI()
    if c <= L:
        DIST[a][b] = c
        DIST[b][a] = c

for k in range(1, N+1):
    for i in range(1, N+1):
        for j in range(1, N+1):
            if DIST[i][j] > DIST[i][k] + DIST[k][j]:
                DIST[i][j] = DIST[i][k] + DIST[k][j]

for i in range(1, N+1):
    for j in range(1, N+1):
        DIST[i][j] = 1 if DIST[i][j] <= L else LG

for k in range(1, N+1):
    for i in range(1, N+1):
        for j in range(1, N+1):
            if DIST[i][j] > DIST[i][k] + DIST[k][j]:
                DIST[i][j] = DIST[i][k] + DIST[k][j]

for i in range(II()):
    st, en = LI()
    if DIST[st][en] >= LG:
        print(-1)
    else:
        print(DIST[st][en] - 1)
