n,m,l=map(int,input().split())
abc=[list(map(int,input().split())) for _ in range(m)]

"""
g=[[] for _ in range(n)]
for a,b,c in abc:
  if c>l:continue
  a,b=a-1,b-1
  g[a].append([b,c])
  g[b].append([a,c])
"""
q=int(input())
st=[list(map(int,input().split())) for _ in range(q)]

def warshall_floyd(d):
  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
inf=float('inf')
d=[[inf]*n for _ in range(n)]

for a,b,c in abc:
  a,b=a-1,b-1
  d[a][b]=c
  d[b][a]=c
for i in range(n):
  d[i][i]=0
d=warshall_floyd(d)
nabc=[]
dd=[[inf]*n for _ in range(n)]
#g=[[] for _ in range(n)]
for i in range(n):
  for j in range(n):
    if d[i][j]<=l:
      dd[i][j]=1
for i in range(n):
  dd[i][i]=0
dd=warshall_floyd(dd)
for s,t in st:
  s,t=s-1,t-1
  tmp=dd[s][t]
  print(max(0,tmp-1) if tmp!=inf else -1)
#print(dd) n,m,l=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l list(map(int,input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split abc=[list(map(int,input().split())) for _ in range(m)] abc [list(map(int,input().split())) for _ in range(m)] """
g=[[] for _ in range(n)]
for a,b,c in abc:
  if c>l:continue
  a,b=a-1,b-1
  g[a].append([b,c])
  g[b].append([a,c])
""" q=int(input()) q int(input()) int input() input list(map(int,input().split())) for _ in range(q) for _ in range(q) _ range(q) range q for _ in range(q) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split st=[list(map(int,input().split())) for _ in range(q)] st [list(map(int,input().split())) for _ in range(q)] def warshall_floyd(d):
  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 warshall_floyd 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 d d inf=float('inf') inf float('inf') float 'inf' [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 a,b,c in abc:
  a,b=a-1,b-1
  d[a][b]=c
  d[b][a]=c a b c abc a,b=a-1,b-1 a a-1 a 1 b b-1 b 1 d[a][b]=c d[a][b] [a] d a b c d[b][a]=c d[b][a] [b] d b a c for i in range(n):
  d[i][i]=0 i range(n) range n d[i][i]=0 d[i][i] [i] d i i 0 d=warshall_floyd(d) d warshall_floyd(d) warshall_floyd d nabc=[] nabc [] [inf]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [inf]*n [inf] inf n dd=[[inf]*n for _ in range(n)] dd [[inf]*n for _ in range(n)] for i in range(n):
  for j in range(n):
    if d[i][j]<=l:
      dd[i][j]=1 i range(n) range n for j in range(n):
    if d[i][j]<=l:
      dd[i][j]=1 j range(n) range n if d[i][j]<=l:
      dd[i][j]=1 d[i][j]<=l d[i][j] [i] d i j l dd[i][j]=1 dd[i][j] [i] dd i j 1 for i in range(n):
  dd[i][i]=0 i range(n) range n dd[i][i]=0 dd[i][i] [i] dd i i 0 dd=warshall_floyd(dd) dd warshall_floyd(dd) warshall_floyd dd for s,t in st:
  s,t=s-1,t-1
  tmp=dd[s][t]
  print(max(0,tmp-1) if tmp!=inf else -1)
#print(dd) s t st s,t=s-1,t-1 s s-1 s 1 t t-1 t 1 tmp=dd[s][t] tmp dd[s][t] [s] dd s t print(max(0,tmp-1) if tmp!=inf else -1) print max(0,tmp-1) if tmp!=inf else -1 tmp!=inf tmp inf max(0,tmp-1) max 0 tmp-1 tmp 1 -1 def warshall_floyd(d):
  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 warshall_floyd(d):
  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 warshall_floyd inf=float('inf') float('inf') inf m,l=map(int,input().split()) map(int,input().split()) m b=a-1,b-1 b-1 b dd=warshall_floyd(dd) warshall_floyd(dd) dd d=[[inf]*n for _ in range(n)] [[inf]*n for _ in range(n)] d s,t=s-1,t-1 s-1 s tmp=dd[s][t] dd[s][t] tmp st=[list(map(int,input().split())) for _ in range(q)] [list(map(int,input().split())) for _ in range(q)] st dd=[[inf]*n for _ in range(n)] [[inf]*n for _ in range(n)] dd n,m,l=map(int,input().split()) map(int,input().split()) n abc=[list(map(int,input().split())) for _ in range(m)] [list(map(int,input().split())) for _ in range(m)] abc nabc=[] [] nabc q=int(input()) int(input()) q a,b=a-1,b-1 a-1 a l=map(int,input().split()) map(int,input().split()) l t=s-1,t-1 t-1 t d=warshall_floyd(d) warshall_floyd(d) d
n,m,l=map(int,input().split())
abc=[list(map(int,input().split())) for _ in range(m)]

"""
g=[[] for _ in range(n)]
for a,b,c in abc:
  if c>l:continue
  a,b=a-1,b-1
  g[a].append([b,c])
  g[b].append([a,c])
"""
q=int(input())
st=[list(map(int,input().split())) for _ in range(q)]

def warshall_floyd(d):
  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
inf=float('inf')
d=[[inf]*n for _ in range(n)]

for a,b,c in abc:
  a,b=a-1,b-1
  d[a][b]=c
  d[b][a]=c
for i in range(n):
  d[i][i]=0
d=warshall_floyd(d)
nabc=[]
dd=[[inf]*n for _ in range(n)]
#g=[[] for _ in range(n)]
for i in range(n):
  for j in range(n):
    if d[i][j]<=l:
      dd[i][j]=1
for i in range(n):
  dd[i][i]=0
dd=warshall_floyd(dd)
for s,t in st:
  s,t=s-1,t-1
  tmp=dd[s][t]
  print(max(0,tmp-1) if tmp!=inf else -1)
#print(dd)