import sys
I=sys.stdin.readlines()
N,M,L=map(int,I[0].split())
a,b,c=0,0,0
D=[[L+1]*N for i in range(N)]
for i in range(M):
  a,b,c=map(int,I[i+1].split())
  a,b=a-1,b-1
  D[a][b]=c
  D[b][a]=c
for i in range(N):
  D[i][i]=0
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])
D2=[[N*N+2]*N for i in range(N)]
for i in range(N):
  D2[i][i]=0
  for j in range(N):
    if D[i][j]<=L:
      D2[i][j]=1
for k in range(N):
  for i in range(N):
    for j in range(N):
      D2[i][j]=min(D2[i][j],D2[i][k]+D2[k][j])
Q=int(I[M+1])
for i in range(Q):
  a,b=map(int,I[i+2+M].split())
  if N<D2[a-1][b-1]:
    print(-1)
  else:
    print(D2[a-1][b-1]-1) import sys sys I=sys.stdin.readlines() I sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines N,M,L=map(int,I[0].split()) N map(int,I[0].split()) map int I[0].split() [0].split [0] I 0 split M L a,b,c=0,0,0 a 0 b 0 c 0 [L+1]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [L+1]*N [L+1] L+1 L 1 N D=[[L+1]*N for i in range(N)] D [[L+1]*N for i in range(N)] for i in range(M):
  a,b,c=map(int,I[i+1].split())
  a,b=a-1,b-1
  D[a][b]=c
  D[b][a]=c i range(M) range M a,b,c=map(int,I[i+1].split()) a map(int,I[i+1].split()) map int I[i+1].split() [i+1].split [i+1] I i+1 i 1 split b c 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 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 [N*N+2]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [N*N+2]*N [N*N+2] N*N+2 N*N N N 2 N D2=[[N*N+2]*N for i in range(N)] D2 [[N*N+2]*N for i in range(N)] for i in range(N):
  D2[i][i]=0
  for j in range(N):
    if D[i][j]<=L:
      D2[i][j]=1 i range(N) range N D2[i][i]=0 D2[i][i] [i] D2 i i 0 for j in range(N):
    if D[i][j]<=L:
      D2[i][j]=1 j range(N) range N if D[i][j]<=L:
      D2[i][j]=1 D[i][j]<=L D[i][j] [i] D i j L D2[i][j]=1 D2[i][j] [i] D2 i j 1 for k in range(N):
  for i in range(N):
    for j in range(N):
      D2[i][j]=min(D2[i][j],D2[i][k]+D2[k][j]) k range(N) range N for i in range(N):
    for j in range(N):
      D2[i][j]=min(D2[i][j],D2[i][k]+D2[k][j]) i range(N) range N for j in range(N):
      D2[i][j]=min(D2[i][j],D2[i][k]+D2[k][j]) j range(N) range N D2[i][j]=min(D2[i][j],D2[i][k]+D2[k][j]) D2[i][j] [i] D2 i j min(D2[i][j],D2[i][k]+D2[k][j]) min D2[i][j] [i] D2 i j D2[i][k]+D2[k][j] D2[i][k] [i] D2 i k D2[k][j] [k] D2 k j Q=int(I[M+1]) Q int(I[M+1]) int I[M+1] I M+1 M 1 for i in range(Q):
  a,b=map(int,I[i+2+M].split())
  if N<D2[a-1][b-1]:
    print(-1)
  else:
    print(D2[a-1][b-1]-1) i range(Q) range Q a,b=map(int,I[i+2+M].split()) a map(int,I[i+2+M].split()) map int I[i+2+M].split() [i+2+M].split [i+2+M] I i+2+M i+2 i 2 M split b if N<D2[a-1][b-1]:
    print(-1)
  else:
    print(D2[a-1][b-1]-1) N<D2[a-1][b-1] N D2[a-1][b-1] [a-1] D2 a-1 a 1 b-1 b 1 print(-1) print -1 print(D2[a-1][b-1]-1) print D2[a-1][b-1]-1 D2[a-1][b-1] [a-1] D2 a-1 a 1 b-1 b 1 1 M,L=map(int,I[0].split()) map(int,I[0].split()) M c=0,0,0 0 c a,b=a-1,b-1 a-1 a a,b=map(int,I[i+2+M].split()) map(int,I[i+2+M].split()) a D2=[[N*N+2]*N for i in range(N)] [[N*N+2]*N for i in range(N)] D2 I=sys.stdin.readlines() sys.stdin.readlines() I D=[[L+1]*N for i in range(N)] [[L+1]*N for i in range(N)] D b,c=map(int,I[i+1].split()) map(int,I[i+1].split()) b c=map(int,I[i+1].split()) map(int,I[i+1].split()) c L=map(int,I[0].split()) map(int,I[0].split()) L a,b,c=map(int,I[i+1].split()) map(int,I[i+1].split()) a b=map(int,I[i+2+M].split()) map(int,I[i+2+M].split()) b b=a-1,b-1 b-1 b Q=int(I[M+1]) int(I[M+1]) Q N,M,L=map(int,I[0].split()) map(int,I[0].split()) N a,b,c=0,0,0 0 a b,c=0,0,0 0 b
import sys
I=sys.stdin.readlines()
N,M,L=map(int,I[0].split())
a,b,c=0,0,0
D=[[L+1]*N for i in range(N)]
for i in range(M):
  a,b,c=map(int,I[i+1].split())
  a,b=a-1,b-1
  D[a][b]=c
  D[b][a]=c
for i in range(N):
  D[i][i]=0
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])
D2=[[N*N+2]*N for i in range(N)]
for i in range(N):
  D2[i][i]=0
  for j in range(N):
    if D[i][j]<=L:
      D2[i][j]=1
for k in range(N):
  for i in range(N):
    for j in range(N):
      D2[i][j]=min(D2[i][j],D2[i][k]+D2[k][j])
Q=int(I[M+1])
for i in range(Q):
  a,b=map(int,I[i+2+M].split())
  if N<D2[a-1][b-1]:
    print(-1)
  else:
    print(D2[a-1][b-1]-1)