import sys
sys.setrecursionlimit(10**9)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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
chk = warshall_floyd(d)

for i in range(N-1):
  for j in range(i+1,N):
    if chk[i][j] <= L:
      a[i][j] = 1
      a[j][i] = 1
ans = warshall_floyd(a)

for s,t in ST:
  answer = ans[s-1][t-1]
  if answer == INF:
      print(-1)
  else:
      print(answer-1) import sys sys sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 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 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 chk = warshall_floyd(d) chk warshall_floyd(d) warshall_floyd d for i in range(N-1):
  for j in range(i+1,N):
    if chk[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 chk[i][j] <= L:
      a[i][j] = 1
      a[j][i] = 1 j range(i+1,N) range i+1 i 1 N if chk[i][j] <= L:
      a[i][j] = 1
      a[j][i] = 1 chk[i][j] <= L chk[i][j] [i] chk 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 ans = warshall_floyd(a) ans warshall_floyd(a) warshall_floyd a for s,t in ST:
  answer = ans[s-1][t-1]
  if answer == INF:
      print(-1)
  else:
      print(answer-1) s t ST answer = ans[s-1][t-1] answer ans[s-1][t-1] [s-1] ans s-1 s 1 t-1 t 1 if answer == INF:
      print(-1)
  else:
      print(answer-1) answer == INF answer INF print(-1) print -1 print(answer-1) print answer-1 answer 1 N,M,L = map(int,readline().split()) map(int,readline().split()) N readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline M,L = map(int,readline().split()) map(int,readline().split()) M ST = [list(map(int,readline().split())) for _ in range(Q)] [list(map(int,readline().split())) for _ in range(Q)] ST 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 ans = warshall_floyd(a) warshall_floyd(a) ans Q = int(readline()) int(readline()) Q ABC = [list(map(int,readline().split())) for _ in range(M)] [list(map(int,readline().split())) for _ in range(M)] ABC a =  [[INF]*N for i in range(N)] [[INF]*N for i in range(N)] a L = map(int,readline().split()) map(int,readline().split()) L d = [[INF]*N for i in range(N)] [[INF]*N for i in range(N)] d read = sys.stdin.buffer.read sys.stdin.buffer.read read answer = ans[s-1][t-1] ans[s-1][t-1] answer chk = warshall_floyd(d) warshall_floyd(d) chk INF = 10**11 10**11 INF readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines
import sys
sys.setrecursionlimit(10**9)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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
chk = warshall_floyd(d)

for i in range(N-1):
  for j in range(i+1,N):
    if chk[i][j] <= L:
      a[i][j] = 1
      a[j][i] = 1
ans = warshall_floyd(a)

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