def W(d):
    #d[i][j]: iからjへの最短距離
    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

##############################
n,w,l= map(int,input().split()) #n:頂点数　w:辺の数

d = [[10**14]*n for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(w):
    x,y,z = map(int,input().split())
    if z>l:
      continue
    x=x-1
    y=y-1
    d[x][y] = z
    d[y][x] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
D=W(d)
G=[[10**4]*n for i in range(n)]
for i in range(n):
  for j in range(n):
    if D[i][j]>l:
      continue
    G[i][j]=1
WW=W(G)
for i in range(int(input())):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  if WW[a][b]>=10**4:
    print(-1)
  else:
    print(WW[a][b]-1) def W(d):
    #d[i][j]: iからjへの最短距離
    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

############################## W 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 n,w,l= map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split w l [10**14]*n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [10**14]*n [10**14] 10**14 10 14 n d = [[10**14]*n for i in range(n)] d [[10**14]*n for i in range(n)] for i in range(w):
    x,y,z = map(int,input().split())
    if z>l:
      continue
    x=x-1
    y=y-1
    d[x][y] = z
    d[y][x] = z i range(w) range w x,y,z = map(int,input().split()) x map(int,input().split()) map int input().split() ().split () input split y z if z>l:
      continue
     z>l z l continue x=x-1 x x-1 x 1 y=y-1 y y-1 y 1 d[x][y] = z d[x][y] [x] d x y z d[y][x] = z d[y][x] [y] d y x z 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=W(d) D W(d) W d [10**4]*n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [10**4]*n [10**4] 10**4 10 4 n G=[[10**4]*n for i in range(n)] G [[10**4]*n for i in range(n)] for i in range(n):
  for j in range(n):
    if D[i][j]>l:
      continue
    G[i][j]=1 i range(n) range n for j in range(n):
    if D[i][j]>l:
      continue
    G[i][j]=1 j range(n) range n if D[i][j]>l:
      continue
     D[i][j]>l D[i][j] [i] D i j l continue G[i][j]=1 G[i][j] [i] G i j 1 WW=W(G) WW W(G) W G for i in range(int(input())):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  if WW[a][b]>=10**4:
    print(-1)
  else:
    print(WW[a][b]-1) i range(int(input())) range int(input()) int input() input a,b=map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b a=a-1 a a-1 a 1 b=b-1 b b-1 b 1 if WW[a][b]>=10**4:
    print(-1)
  else:
    print(WW[a][b]-1) WW[a][b]>=10**4 WW[a][b] [a] WW a b 10**4 10 4 print(-1) print -1 print(WW[a][b]-1) print WW[a][b]-1 WW[a][b] [a] WW a b 1 a,b=map(int,input().split()) map(int,input().split()) a z = map(int,input().split()) map(int,input().split()) z WW=W(G) W(G) WW a=a-1 a-1 a G=[[10**4]*n for i in range(n)] [[10**4]*n for i in range(n)] G y,z = map(int,input().split()) map(int,input().split()) y b=b-1 b-1 b def W(d):
    #d[i][j]: iからjへの最短距離
    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 W(d):
    #d[i][j]: iからjへの最短距離
    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

############################## W d = [[10**14]*n for i in range(n)] [[10**14]*n for i in range(n)] d b=map(int,input().split()) map(int,input().split()) b l= map(int,input().split()) map(int,input().split()) l D=W(d) W(d) D n,w,l= map(int,input().split()) map(int,input().split()) n w,l= map(int,input().split()) map(int,input().split()) w y=y-1 y-1 y x,y,z = map(int,input().split()) map(int,input().split()) x x=x-1 x-1 x
def W(d):
    #d[i][j]: iからjへの最短距離
    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

##############################
n,w,l= map(int,input().split()) #n:頂点数　w:辺の数

d = [[10**14]*n for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(w):
    x,y,z = map(int,input().split())
    if z>l:
      continue
    x=x-1
    y=y-1
    d[x][y] = z
    d[y][x] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
D=W(d)
G=[[10**4]*n for i in range(n)]
for i in range(n):
  for j in range(n):
    if D[i][j]>l:
      continue
    G[i][j]=1
WW=W(G)
for i in range(int(input())):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  if WW[a][b]>=10**4:
    print(-1)
  else:
    print(WW[a][b]-1)