N,M,L=map(int, input().split())
def warshall_floyd(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

d=[[float("inf")]*N for i in range(N)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(M):
    x,y,z=map(int,input().split())
    d[x-1][y-1]=z
    d[y-1][x-1]=z
for i in range(N):
    d[i][i]=0 #自身のところに行くコストは０
D=warshall_floyd(d)
E=[[float("inf")]*N for i in range(N)] 
for i in range(N):
  for j in range(N):
    if D[i][j]==0:
      E[i][j]=0
    elif D[i][j]<=L:
      E[i][j]=1
F=warshall_floyd(E)
N=int(input())
for i in range(N):
  x,y=map(int,input().split())
  if F[x-1][y-1]==float("inf"):
    print(-1)
  else:
    print(F[x-1][y-1]-1) N,M,L=map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L def warshall_floyd(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 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 [float("inf")]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [float("inf")]*N [float("inf")] float("inf") float "inf" N d=[[float("inf")]*N for i in range(N)] d [[float("inf")]*N for i in range(N)] for i in range(M):
    x,y,z=map(int,input().split())
    d[x-1][y-1]=z
    d[y-1][x-1]=z i range(M) range M x,y,z=map(int,input().split()) x map(int,input().split()) map int input().split() ().split () input split y z 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 #自身のところに行くコストは０ 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 [float("inf")]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [float("inf")]*N [float("inf")] float("inf") float "inf" N E=[[float("inf")]*N for i in range(N)] E [[float("inf")]*N for i in range(N)] for i in range(N):
  for j in range(N):
    if D[i][j]==0:
      E[i][j]=0
    elif D[i][j]<=L:
      E[i][j]=1 i range(N) range N for j in range(N):
    if D[i][j]==0:
      E[i][j]=0
    elif D[i][j]<=L:
      E[i][j]=1 j range(N) range N if D[i][j]==0:
      E[i][j]=0
    elif D[i][j]<=L:
      E[i][j]=1 D[i][j]==0 D[i][j] [i] D i j 0 E[i][j]=0 E[i][j] [i] E i j 0 elif D[i][j]<=L:
      E[i][j]=1 D[i][j]<=L D[i][j] [i] D i j L E[i][j]=1 E[i][j] [i] E i j 1 F=warshall_floyd(E) F warshall_floyd(E) warshall_floyd E N=int(input()) N int(input()) int input() input for i in range(N):
  x,y=map(int,input().split())
  if F[x-1][y-1]==float("inf"):
    print(-1)
  else:
    print(F[x-1][y-1]-1) i range(N) range N x,y=map(int,input().split()) x map(int,input().split()) map int input().split() ().split () input split y if F[x-1][y-1]==float("inf"):
    print(-1)
  else:
    print(F[x-1][y-1]-1) F[x-1][y-1]==float("inf") F[x-1][y-1] [x-1] F x-1 x 1 y-1 y 1 float("inf") float "inf" print(-1) print -1 print(F[x-1][y-1]-1) print F[x-1][y-1]-1 F[x-1][y-1] [x-1] F x-1 x 1 y-1 y 1 1 D=warshall_floyd(d) warshall_floyd(d) D x,y,z=map(int,input().split()) map(int,input().split()) x y=map(int,input().split()) map(int,input().split()) y F=warshall_floyd(E) warshall_floyd(E) F E=[[float("inf")]*N for i in range(N)] [[float("inf")]*N for i in range(N)] E def warshall_floyd(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 warshall_floyd(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 warshall_floyd M,L=map(int, input().split()) map(int, input().split()) M d=[[float("inf")]*N for i in range(N)] [[float("inf")]*N for i in range(N)] d N,M,L=map(int, input().split()) map(int, input().split()) N L=map(int, input().split()) map(int, input().split()) L z=map(int,input().split()) map(int,input().split()) z x,y=map(int,input().split()) map(int,input().split()) x y,z=map(int,input().split()) map(int,input().split()) y N=int(input()) int(input()) N
N,M,L=map(int, input().split())
def warshall_floyd(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

d=[[float("inf")]*N for i in range(N)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(M):
    x,y,z=map(int,input().split())
    d[x-1][y-1]=z
    d[y-1][x-1]=z
for i in range(N):
    d[i][i]=0 #自身のところに行くコストは０
D=warshall_floyd(d)
E=[[float("inf")]*N for i in range(N)] 
for i in range(N):
  for j in range(N):
    if D[i][j]==0:
      E[i][j]=0
    elif D[i][j]<=L:
      E[i][j]=1
F=warshall_floyd(E)
N=int(input())
for i in range(N):
  x,y=map(int,input().split())
  if F[x-1][y-1]==float("inf"):
    print(-1)
  else:
    print(F[x-1][y-1]-1)