import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

N,M,L = map(int,readline().split())
ABC = [list(map(int,readline().split())) for _ in range(M)]
Q = int(readline())
ST = [list(map(int,readline().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 = 10**11
d = [[INF]*N for i in range(N)] 
a =  [[INF]*N for i in range(N)] 
for x,y,z in ABC:
    if z <= L:
      d[x-1][y-1] = z
      d[y-1][x-1] = z
for i in range(N):
    d[i][i] = 0
    a[i][i] = 1
d = csr_matrix(d)
d = floyd_warshall(csgraph=d)

for i in range(N-1):
  for j in range(i+1,N):
    if d[i][j] <= L:
      a[i][j] = 1
      a[j][i] = 1
a = csr_matrix(a)
a = floyd_warshall(csgraph=a)

for s,t in ST:
  ans = a[s-1][t-1]
  if ans == INF:
      print(-1)
  else:
      print(int(ans)-1) import sys sys read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall N,M,L = map(int,readline().split()) N map(int,readline().split()) map int readline().split() ().split () readline split M L list(map(int,readline().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) list(map(int,readline().split())) list map(int,readline().split()) map int readline().split() ().split () readline split ABC = [list(map(int,readline().split())) for _ in range(M)] ABC [list(map(int,readline().split())) for _ in range(M)] Q = int(readline()) Q int(readline()) int readline() readline list(map(int,readline().split())) for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) list(map(int,readline().split())) list map(int,readline().split()) map int readline().split() ().split () readline split ST = [list(map(int,readline().split())) for _ in range(Q)] ST [list(map(int,readline().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 = 10**11 INF 10**11 10 11 [INF]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [INF]*N [INF] INF N d = [[INF]*N for i in range(N)] d [[INF]*N for i in range(N)] [INF]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [INF]*N [INF] INF N a =  [[INF]*N for i in range(N)] a [[INF]*N for i in range(N)] for x,y,z in ABC:
    if z <= L:
      d[x-1][y-1] = z
      d[y-1][x-1] = z x y z ABC if z <= L:
      d[x-1][y-1] = z
      d[y-1][x-1] = z z <= L z L d[x-1][y-1] = z d[x-1][y-1] [x-1] d x-1 x 1 y-1 y 1 z d[y-1][x-1] = z d[y-1][x-1] [y-1] d y-1 y 1 x-1 x 1 z for i in range(N):
    d[i][i] = 0
    a[i][i] = 1 i range(N) range N d[i][i] = 0 d[i][i] [i] d i i 0 a[i][i] = 1 a[i][i] [i] a i i 1 d = csr_matrix(d) d csr_matrix(d) csr_matrix d d = floyd_warshall(csgraph=d) d floyd_warshall(csgraph=d) floyd_warshall csgraph=d csgraph d for i in range(N-1):
  for j in range(i+1,N):
    if d[i][j] <= L:
      a[i][j] = 1
      a[j][i] = 1 i range(N-1) range N-1 N 1 for j in range(i+1,N):
    if d[i][j] <= L:
      a[i][j] = 1
      a[j][i] = 1 j range(i+1,N) range i+1 i 1 N if d[i][j] <= L:
      a[i][j] = 1
      a[j][i] = 1 d[i][j] <= L d[i][j] [i] d i j L a[i][j] = 1 a[i][j] [i] a i j 1 a[j][i] = 1 a[j][i] [j] a j i 1 a = csr_matrix(a) a csr_matrix(a) csr_matrix a a = floyd_warshall(csgraph=a) a floyd_warshall(csgraph=a) floyd_warshall csgraph=a csgraph a for s,t in ST:
  ans = a[s-1][t-1]
  if ans == INF:
      print(-1)
  else:
      print(int(ans)-1) s t ST ans = a[s-1][t-1] ans a[s-1][t-1] [s-1] a s-1 s 1 t-1 t 1 if ans == INF:
      print(-1)
  else:
      print(int(ans)-1) ans == INF ans INF print(-1) print -1 print(int(ans)-1) print int(ans)-1 int(ans) int ans 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 d = [[INF]*N for i in range(N)] [[INF]*N for i in range(N)] d a = csr_matrix(a) csr_matrix(a) a readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines ans = a[s-1][t-1] a[s-1][t-1] ans N,M,L = map(int,readline().split()) map(int,readline().split()) N Q = int(readline()) int(readline()) Q M,L = map(int,readline().split()) map(int,readline().split()) M d = floyd_warshall(csgraph=d) floyd_warshall(csgraph=d) d a =  [[INF]*N for i in range(N)] [[INF]*N for i in range(N)] a INF = 10**11 10**11 INF ABC = [list(map(int,readline().split())) for _ in range(M)] [list(map(int,readline().split())) for _ in range(M)] ABC ST = [list(map(int,readline().split())) for _ in range(Q)] [list(map(int,readline().split())) for _ in range(Q)] ST a = floyd_warshall(csgraph=a) floyd_warshall(csgraph=a) a read = sys.stdin.buffer.read sys.stdin.buffer.read read L = map(int,readline().split()) map(int,readline().split()) L readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline d = csr_matrix(d) csr_matrix(d) d
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

N,M,L = map(int,readline().split())
ABC = [list(map(int,readline().split())) for _ in range(M)]
Q = int(readline())
ST = [list(map(int,readline().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 = 10**11
d = [[INF]*N for i in range(N)] 
a =  [[INF]*N for i in range(N)] 
for x,y,z in ABC:
    if z <= L:
      d[x-1][y-1] = z
      d[y-1][x-1] = z
for i in range(N):
    d[i][i] = 0
    a[i][i] = 1
d = csr_matrix(d)
d = floyd_warshall(csgraph=d)

for i in range(N-1):
  for j in range(i+1,N):
    if d[i][j] <= L:
      a[i][j] = 1
      a[j][i] = 1
a = csr_matrix(a)
a = floyd_warshall(csgraph=a)

for s,t in ST:
  ans = a[s-1][t-1]
  if ans == INF:
      print(-1)
  else:
      print(int(ans)-1)