import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

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


n, m, l = na()
abc = nan(m)
q = ni()
st = nan(q)

g = [[] for _ in range(n)]
dist = [[inf] * n for _ in range(n)]
for i in range(m):
    a, b, c = abc[i]
    a -= 1
    b -= 1
    dist[a][b] = c
    dist[b][a] = c

floyd_warshall(n, dist)

ans = [[inf] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if dist[i][j] <= l:
            ans[i][j] = 1
            ans[j][i] = 1

floyd_warshall(n, ans)

for i in range(q):
    s, t = st[i]
    s -= 1
    t -= 1
    if ans[s][t] >= inf:
        print(-1)
    else:
        print(ans[s][t] - 1) import sys sys stdin = sys.stdin stdin sys.stdin sys stdin inf = 1 << 60 inf 1 << 60 1 60 mod = 1000000007 mod 1000000007 sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 ni      = lambda: int(ns()) ni lambda: int(ns()) int(ns()) int ns() ns ni() for _ in range(y) for _ in range(y) _ range(y) range y for _ in range(y) ni() ni nin     = lambda y: [ni() for _ in range(y)] nin lambda y: [ni() for _ in range(y)] [ni() for _ in range(y)] y na      = lambda: list(map(int, stdin.readline().split())) na lambda: list(map(int, stdin.readline().split())) list(map(int, stdin.readline().split())) list map(int, stdin.readline().split()) map int stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split na() for _ in range(y) for _ in range(y) _ range(y) range y for _ in range(y) na() na nan     = lambda y: [na() for _ in range(y)] nan lambda y: [na() for _ in range(y)] [na() for _ in range(y)] y nf      = lambda: float(ns()) nf lambda: float(ns()) float(ns()) float ns() ns nf() for _ in range(y) for _ in range(y) _ range(y) range y for _ in range(y) nf() nf nfn     = lambda y: [nf() for _ in range(y)] nfn lambda y: [nf() for _ in range(y)] [nf() for _ in range(y)] y nfa     = lambda: list(map(float, stdin.readline().split())) nfa lambda: list(map(float, stdin.readline().split())) list(map(float, stdin.readline().split())) list map(float, stdin.readline().split()) map float stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split nfa() for _ in range(y) for _ in range(y) _ range(y) range y for _ in range(y) nfa() nfa nfan    = lambda y: [nfa() for _ in range(y)] nfan lambda y: [nfa() for _ in range(y)] [nfa() for _ in range(y)] y ns      = lambda: stdin.readline().rstrip() ns lambda: stdin.readline().rstrip() stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip ns() for _ in range(y) for _ in range(y) _ range(y) range y for _ in range(y) ns() ns nsn     = lambda y: [ns() for _ in range(y)] nsn lambda y: [ns() for _ in range(y)] [ns() for _ in range(y)] y list(ns()) for _ in range(y) for _ in range(y) _ range(y) range y for _ in range(y) list(ns()) list ns() ns ncl     = lambda y: [list(ns()) for _ in range(y)] ncl lambda y: [list(ns()) for _ in range(y)] [list(ns()) for _ in range(y)] y nas     = lambda: stdin.readline().split() nas lambda: stdin.readline().split() stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split def floyd_warshall(n, dist):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]) floyd_warshall for i in range(n):
        for j in range(n):
            for k in range(n):
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]) i range(n) range n for j in range(n):
            for k in range(n):
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]) j range(n) range n for k in range(n):
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]) k range(n) range n dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]) dist[j][k] [j] dist j k min(dist[j][k], dist[j][i] + dist[i][k]) min dist[j][k] [j] dist j k dist[j][i] + dist[i][k] dist[j][i] [j] dist j i dist[i][k] [i] dist i k n n dist dist n, m, l = na() n na() na m l abc = nan(m) abc nan(m) nan m q = ni() q ni() ni st = nan(q) st nan(q) nan q [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] g = [[] for _ in range(n)] g [[] for _ in range(n)] [inf] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [inf] * n [inf] inf n dist = [[inf] * n for _ in range(n)] dist [[inf] * n for _ in range(n)] for i in range(m):
    a, b, c = abc[i]
    a -= 1
    b -= 1
    dist[a][b] = c
    dist[b][a] = c i range(m) range m a, b, c = abc[i] a abc[i] abc i b c a -= 1 a 1 b -= 1 b 1 dist[a][b] = c dist[a][b] [a] dist a b c dist[b][a] = c dist[b][a] [b] dist b a c floyd_warshall(n, dist) floyd_warshall n dist [inf] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [inf] * n [inf] inf n ans = [[inf] * n for _ in range(n)] ans [[inf] * n for _ in range(n)] for i in range(n):
    for j in range(n):
        if dist[i][j] <= l:
            ans[i][j] = 1
            ans[j][i] = 1 i range(n) range n for j in range(n):
        if dist[i][j] <= l:
            ans[i][j] = 1
            ans[j][i] = 1 j range(n) range n if dist[i][j] <= l:
            ans[i][j] = 1
            ans[j][i] = 1 dist[i][j] <= l dist[i][j] [i] dist i j l ans[i][j] = 1 ans[i][j] [i] ans i j 1 ans[j][i] = 1 ans[j][i] [j] ans j i 1 floyd_warshall(n, ans) floyd_warshall n ans for i in range(q):
    s, t = st[i]
    s -= 1
    t -= 1
    if ans[s][t] >= inf:
        print(-1)
    else:
        print(ans[s][t] - 1) i range(q) range q s, t = st[i] s st[i] st i t s -= 1 s 1 t -= 1 t 1 if ans[s][t] >= inf:
        print(-1)
    else:
        print(ans[s][t] - 1) ans[s][t] >= inf ans[s][t] [s] ans s t inf print(-1) print -1 print(ans[s][t] - 1) print ans[s][t] - 1 ans[s][t] [s] ans s t 1 st = nan(q) nan(q) st nas     = lambda: stdin.readline().split() lambda: stdin.readline().split() nas mod = 1000000007 1000000007 mod ns      = lambda: stdin.readline().rstrip() lambda: stdin.readline().rstrip() ns ni      = lambda: int(ns()) lambda: int(ns()) ni l = na() na() l abc = nan(m) nan(m) abc inf = 1 << 60 1 << 60 inf nfan    = lambda y: [nfa() for _ in range(y)] lambda y: [nfa() for _ in range(y)] nfan stdin = sys.stdin sys.stdin stdin t -= 1 1 t nan     = lambda y: [na() for _ in range(y)] lambda y: [na() for _ in range(y)] nan nf      = lambda: float(ns()) lambda: float(ns()) nf b, c = abc[i] abc[i] b na      = lambda: list(map(int, stdin.readline().split())) lambda: list(map(int, stdin.readline().split())) na g = [[] for _ in range(n)] [[] for _ in range(n)] g s -= 1 1 s def floyd_warshall(n, dist):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]) def floyd_warshall(n, dist):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]) floyd_warshall t = st[i] st[i] t nin     = lambda y: [ni() for _ in range(y)] lambda y: [ni() for _ in range(y)] nin nfa     = lambda: list(map(float, stdin.readline().split())) lambda: list(map(float, stdin.readline().split())) nfa s, t = st[i] st[i] s c = abc[i] abc[i] c a -= 1 1 a ncl     = lambda y: [list(ns()) for _ in range(y)] lambda y: [list(ns()) for _ in range(y)] ncl b -= 1 1 b q = ni() ni() q a, b, c = abc[i] abc[i] a dist = [[inf] * n for _ in range(n)] [[inf] * n for _ in range(n)] dist nsn     = lambda y: [ns() for _ in range(y)] lambda y: [ns() for _ in range(y)] nsn m, l = na() na() m ans = [[inf] * n for _ in range(n)] [[inf] * n for _ in range(n)] ans nfn     = lambda y: [nf() for _ in range(y)] lambda y: [nf() for _ in range(y)] nfn n, m, l = na() na() n
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

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


n, m, l = na()
abc = nan(m)
q = ni()
st = nan(q)

g = [[] for _ in range(n)]
dist = [[inf] * n for _ in range(n)]
for i in range(m):
    a, b, c = abc[i]
    a -= 1
    b -= 1
    dist[a][b] = c
    dist[b][a] = c

floyd_warshall(n, dist)

ans = [[inf] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if dist[i][j] <= l:
            ans[i][j] = 1
            ans[j][i] = 1

floyd_warshall(n, ans)

for i in range(q):
    s, t = st[i]
    s -= 1
    t -= 1
    if ans[s][t] >= inf:
        print(-1)
    else:
        print(ans[s][t] - 1)