import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m,l = list(map(int, input().split()))
from collections import defaultdict
ns = defaultdict(set)
for i in range(m):
    a,b,c = map(int, input().split())
    a-=1
    b-=1
    if c<=l:
        ns[a].add((c,b))
        ns[b].add((c,a))

def wf(ns):
    """全頂点間距離
    """
    d = [[float("inf")]*n for _ in range(n)]
    for i in range(n):
        for t,j in ns[i]:
            d[i][j] = t
        d[i][i] = 0
    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])
    return d
dist = wf(ns)
ns2 = defaultdict(set)
for i in range(n):
    for j in range(i+1,n):
        if dist[i][j]<=l:
            ns2[i].add((1,j))
            ns2[j].add((1,i))
ddist = wf(ns2)
q = int(input())
ans = [None]*q
for i in range(q):
    s,t = map(int, input().split())
    s-=1
    t-=1
    if dist[s][t]==float("inf"):
        ans[i] = -1
    else:
        ans[i] = ddist[s][t] - 1
write("\n".join(map(str, ans))) import sys sys input = lambda : sys.stdin.readline().rstrip() input lambda : sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip sys.setrecursionlimit(max(1000, 10**9)) sys.setrecursionlimit sys setrecursionlimit max(1000, 10**9) max 1000 10**9 10 9 write = lambda x: sys.stdout.write(x+"\n") write lambda x: sys.stdout.write(x+"\n") sys.stdout.write(x+"\n") sys.stdout.write sys.stdout sys stdout write x+"\n" x "\n" x 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 from collections import defaultdict ns = defaultdict(set) ns defaultdict(set) defaultdict set for i in range(m):
    a,b,c = map(int, input().split())
    a-=1
    b-=1
    if c<=l:
        ns[a].add((c,b))
        ns[b].add((c,a)) 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 a-=1 a 1 b-=1 b 1 if c<=l:
        ns[a].add((c,b))
        ns[b].add((c,a)) c<=l c l ns[a].add((c,b)) [a].add [a] ns a add (c,b) c b ns[b].add((c,a)) [b].add [b] ns b add (c,a) c a def wf(ns):
    """全頂点間距離
    """
    d = [[float("inf")]*n for _ in range(n)]
    for i in range(n):
        for t,j in ns[i]:
            d[i][j] = t
        d[i][i] = 0
    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])
    return d wf """全頂点間距離
    """ [float("inf")]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [float("inf")]*n [float("inf")] float("inf") float "inf" n d = [[float("inf")]*n for _ in range(n)] d [[float("inf")]*n for _ in range(n)] for i in range(n):
        for t,j in ns[i]:
            d[i][j] = t
        d[i][i] = 0
     i range(n) range n for t,j in ns[i]:
            d[i][j] = t
         t j ns[i] ns i d[i][j] = t d[i][j] [i] d i j t d[i][i] = 0 d[i][i] [i] d i i 0 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 return d d ns ns dist = wf(ns) dist wf(ns) wf ns ns2 = defaultdict(set) ns2 defaultdict(set) defaultdict set for i in range(n):
    for j in range(i+1,n):
        if dist[i][j]<=l:
            ns2[i].add((1,j))
            ns2[j].add((1,i)) i range(n) range n for j in range(i+1,n):
        if dist[i][j]<=l:
            ns2[i].add((1,j))
            ns2[j].add((1,i)) j range(i+1,n) range i+1 i 1 n if dist[i][j]<=l:
            ns2[i].add((1,j))
            ns2[j].add((1,i)) dist[i][j]<=l dist[i][j] [i] dist i j l ns2[i].add((1,j)) [i].add [i] ns2 i add (1,j) 1 j ns2[j].add((1,i)) [j].add [j] ns2 j add (1,i) 1 i ddist = wf(ns2) ddist wf(ns2) wf ns2 q = int(input()) q int(input()) int input() input ans = [None]*q ans [None]*q [None] None q for i in range(q):
    s,t = map(int, input().split())
    s-=1
    t-=1
    if dist[s][t]==float("inf"):
        ans[i] = -1
    else:
        ans[i] = ddist[s][t] - 1 i range(q) range q s,t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t s-=1 s 1 t-=1 t 1 if dist[s][t]==float("inf"):
        ans[i] = -1
    else:
        ans[i] = ddist[s][t] - 1 dist[s][t]==float("inf") dist[s][t] [s] dist s t float("inf") float "inf" ans[i] = -1 ans[i] ans i -1 ans[i] = ddist[s][t] - 1 ans[i] ans i ddist[s][t] - 1 ddist[s][t] [s] ddist s t 1 write("\n".join(map(str, ans))) write "\n".join(map(str, ans)) "\n".join "\n" join map(str, ans) map str ans input = lambda : sys.stdin.readline().rstrip() lambda : sys.stdin.readline().rstrip() input ns2 = defaultdict(set) defaultdict(set) ns2 s-=1 1 s l = list(map(int, input().split())) list(map(int, input().split())) l a,b,c = map(int, input().split()) map(int, input().split()) a n,m,l = list(map(int, input().split())) list(map(int, input().split())) n b,c = map(int, input().split()) map(int, input().split()) b c = map(int, input().split()) map(int, input().split()) c q = int(input()) int(input()) q def wf(ns):
    """全頂点間距離
    """
    d = [[float("inf")]*n for _ in range(n)]
    for i in range(n):
        for t,j in ns[i]:
            d[i][j] = t
        d[i][i] = 0
    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])
    return d def wf(ns):
    """全頂点間距離
    """
    d = [[float("inf")]*n for _ in range(n)]
    for i in range(n):
        for t,j in ns[i]:
            d[i][j] = t
        d[i][i] = 0
    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])
    return d wf t = map(int, input().split()) map(int, input().split()) t dist = wf(ns) wf(ns) dist a-=1 1 a s,t = map(int, input().split()) map(int, input().split()) s ddist = wf(ns2) wf(ns2) ddist ans = [None]*q [None]*q ans write = lambda x: sys.stdout.write(x+"\n") lambda x: sys.stdout.write(x+"\n") write ns = defaultdict(set) defaultdict(set) ns m,l = list(map(int, input().split())) list(map(int, input().split())) m b-=1 1 b t-=1 1 t
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m,l = list(map(int, input().split()))
from collections import defaultdict
ns = defaultdict(set)
for i in range(m):
    a,b,c = map(int, input().split())
    a-=1
    b-=1
    if c<=l:
        ns[a].add((c,b))
        ns[b].add((c,a))

def wf(ns):
    """全頂点間距離
    """
    d = [[float("inf")]*n for _ in range(n)]
    for i in range(n):
        for t,j in ns[i]:
            d[i][j] = t
        d[i][i] = 0
    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])
    return d
dist = wf(ns)
ns2 = defaultdict(set)
for i in range(n):
    for j in range(i+1,n):
        if dist[i][j]<=l:
            ns2[i].add((1,j))
            ns2[j].add((1,i))
ddist = wf(ns2)
q = int(input())
ans = [None]*q
for i in range(q):
    s,t = map(int, input().split())
    s-=1
    t-=1
    if dist[s][t]==float("inf"):
        ans[i] = -1
    else:
        ans[i] = ddist[s][t] - 1
write("\n".join(map(str, ans)))