import sys
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 9999999999

def ddprint(x):
  if DBG:
    print(x)

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

n,m,l = inm()
dst = [ [] for i in range(n) ]
for i in range(m):
    a,b,c = inm()
    dst[a-1].append((b-1,c))
    dst[b-1].append((a-1,c))

dist1 = [ [BIG]*n for i in range(n) ]
for i in range(n):
    dist1[i][i] = 0
    for j,c in dst[i]:
        dist1[i][j] = c

ws(dist1)

dist2 = [ [BIG]*n for i in range(n) ]
for i in range(n):
    dist2[i][i] = 0
    for j in range(n):
        if dist1[i][j] <= l:
            dist2[i][j] = 1

ws(dist2)

q = inn()
for i in range(q):
    s,t = inm()
    d = dist2[s-1][t-1]
    print(d-1 if d<BIG else -1) import sys sys printn = lambda x: sys.stdout.write(x) printn lambda x: sys.stdout.write(x) sys.stdout.write(x) sys.stdout.write sys.stdout sys stdout write x x inn = lambda : int(input()) inn lambda : int(input()) int(input()) int input() input inl   = lambda: list(map(int, input().split())) inl lambda: list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split inm   = lambda:      map(int, input().split()) inm lambda:      map(int, input().split()) map(int, input().split()) map int input().split() ().split () input split DBG = True DBG True BIG = 9999999999 BIG 9999999999 def ddprint(x):
  if DBG:
    print(x) ddprint if DBG:
    print(x) DBG print(x) print x x x def ws(dist):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j],
                              dist[i][k]+dist[k][j]) ws for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j],
                              dist[i][k]+dist[k][j]) k range(n) range n for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j],
                              dist[i][k]+dist[k][j]) i range(n) range n for j in range(n):
                dist[i][j] = min(dist[i][j],
                              dist[i][k]+dist[k][j]) j range(n) range n dist[i][j] = min(dist[i][j],
                              dist[i][k]+dist[k][j]) dist[i][j] [i] dist i j min(dist[i][j],
                              dist[i][k]+dist[k][j]) min 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 dist n,m,l = inm() n inm() inm m l [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] dst = [ [] for i in range(n) ] dst [ [] for i in range(n) ] for i in range(m):
    a,b,c = inm()
    dst[a-1].append((b-1,c))
    dst[b-1].append((a-1,c)) i range(m) range m a,b,c = inm() a inm() inm b c dst[a-1].append((b-1,c)) [a-1].append [a-1] dst a-1 a 1 append (b-1,c) b-1 b 1 c dst[b-1].append((a-1,c)) [b-1].append [b-1] dst b-1 b 1 append (a-1,c) a-1 a 1 c [BIG]*n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [BIG]*n [BIG] BIG n dist1 = [ [BIG]*n for i in range(n) ] dist1 [ [BIG]*n for i in range(n) ] for i in range(n):
    dist1[i][i] = 0
    for j,c in dst[i]:
        dist1[i][j] = c i range(n) range n dist1[i][i] = 0 dist1[i][i] [i] dist1 i i 0 for j,c in dst[i]:
        dist1[i][j] = c j c dst[i] dst i dist1[i][j] = c dist1[i][j] [i] dist1 i j c ws(dist1) ws dist1 [BIG]*n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [BIG]*n [BIG] BIG n dist2 = [ [BIG]*n for i in range(n) ] dist2 [ [BIG]*n for i in range(n) ] for i in range(n):
    dist2[i][i] = 0
    for j in range(n):
        if dist1[i][j] <= l:
            dist2[i][j] = 1 i range(n) range n dist2[i][i] = 0 dist2[i][i] [i] dist2 i i 0 for j in range(n):
        if dist1[i][j] <= l:
            dist2[i][j] = 1 j range(n) range n if dist1[i][j] <= l:
            dist2[i][j] = 1 dist1[i][j] <= l dist1[i][j] [i] dist1 i j l dist2[i][j] = 1 dist2[i][j] [i] dist2 i j 1 ws(dist2) ws dist2 q = inn() q inn() inn for i in range(q):
    s,t = inm()
    d = dist2[s-1][t-1]
    print(d-1 if d<BIG else -1) i range(q) range q s,t = inm() s inm() inm t d = dist2[s-1][t-1] d dist2[s-1][t-1] [s-1] dist2 s-1 s 1 t-1 t 1 print(d-1 if d<BIG else -1) print d-1 if d<BIG else -1 d<BIG d BIG d-1 d 1 -1 BIG = 9999999999 9999999999 BIG inn = lambda : int(input()) lambda : int(input()) inn dst = [ [] for i in range(n) ] [ [] for i in range(n) ] dst c = inm() inm() c q = inn() inn() q def ddprint(x):
  if DBG:
    print(x) def ddprint(x):
  if DBG:
    print(x) ddprint dist1 = [ [BIG]*n for i in range(n) ] [ [BIG]*n for i in range(n) ] dist1 s,t = inm() inm() s DBG = True True DBG d = dist2[s-1][t-1] dist2[s-1][t-1] d t = inm() inm() t printn = lambda x: sys.stdout.write(x) lambda x: sys.stdout.write(x) printn inm   = lambda:      map(int, input().split()) lambda:      map(int, input().split()) inm def ws(dist):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j],
                              dist[i][k]+dist[k][j]) def ws(dist):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j],
                              dist[i][k]+dist[k][j]) ws inl   = lambda: list(map(int, input().split())) lambda: list(map(int, input().split())) inl b,c = inm() inm() b n,m,l = inm() inm() n a,b,c = inm() inm() a dist2 = [ [BIG]*n for i in range(n) ] [ [BIG]*n for i in range(n) ] dist2 m,l = inm() inm() m l = inm() inm() l
import sys
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 9999999999

def ddprint(x):
  if DBG:
    print(x)

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

n,m,l = inm()
dst = [ [] for i in range(n) ]
for i in range(m):
    a,b,c = inm()
    dst[a-1].append((b-1,c))
    dst[b-1].append((a-1,c))

dist1 = [ [BIG]*n for i in range(n) ]
for i in range(n):
    dist1[i][i] = 0
    for j,c in dst[i]:
        dist1[i][j] = c

ws(dist1)

dist2 = [ [BIG]*n for i in range(n) ]
for i in range(n):
    dist2[i][i] = 0
    for j in range(n):
        if dist1[i][j] <= l:
            dist2[i][j] = 1

ws(dist2)

q = inn()
for i in range(q):
    s,t = inm()
    d = dist2[s-1][t-1]
    print(d-1 if d<BIG else -1)
