import sys

N,M,L=map(int, sys.stdin.readline().split())

d=[  [ float("inf") for j in range(N+1) ]  for i in range(N+1) ]

for _ in range(M):
    a,b,c=map(int, sys.stdin.readline().split())
    d[a][b]=c
    d[b][a]=c
    d[a][a]=0
    d[b][b]=0

for k in range(1,N+1):
	for i in range(1,N+1):
		for j in range(1,N+1):
			d[i][j]=min(d[i][j], d[i][k]+d[k][j])

e=[  [ float("inf") for j in range(N+1) ]  for i in range(N+1) ]
for i in range(1,N+1):
    for j in range(i,N+1):
        if i==j:
            e[i][j]=0
            e[j][i]=0
        elif d[i][j]<=L:
            e[i][j]=1
            e[j][i]=1

for k in range(1,N+1):
	for i in range(1,N+1):
		for j in range(1,N+1):
			e[i][j]=min(e[i][j], e[i][k]+e[k][j])


Q=input()
for _ in range(Q):
    s,t=map(int, sys.stdin.readline().split())
    if e[s][t]==float("inf"):
        print -1
    else:
        print e[s][t]-1 import sys sys N,M,L=map(int, sys.stdin.readline().split()) N map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split M L [ float("inf") for j in range(N+1) ]  for i in range(N+1) for i in range(N+1) i range(N+1) range N+1 N 1 for i in range(N+1) [ float("inf") for j in range(N+1) ] d=[  [ float("inf") for j in range(N+1) ]  for i in range(N+1) ] d [  [ float("inf") for j in range(N+1) ]  for i in range(N+1) ] for _ in range(M):
    a,b,c=map(int, sys.stdin.readline().split())
    d[a][b]=c
    d[b][a]=c
    d[a][a]=0
    d[b][b]=0 _ range(M) range M a,b,c=map(int, sys.stdin.readline().split()) a map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split b c d[a][b]=c d[a][b] [a] d a b c d[b][a]=c d[b][a] [b] d b a c d[a][a]=0 d[a][a] [a] d a a 0 d[b][b]=0 d[b][b] [b] d b b 0 for k in range(1,N+1):
	for i in range(1,N+1):
		for j in range(1,N+1):
			d[i][j]=min(d[i][j], d[i][k]+d[k][j]) k range(1,N+1) range 1 N+1 N 1 for i in range(1,N+1):
		for j in range(1,N+1):
			d[i][j]=min(d[i][j], d[i][k]+d[k][j]) i range(1,N+1) range 1 N+1 N 1 for j in range(1,N+1):
			d[i][j]=min(d[i][j], d[i][k]+d[k][j]) j range(1,N+1) range 1 N+1 N 1 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 [ float("inf") for j in range(N+1) ]  for i in range(N+1) for i in range(N+1) i range(N+1) range N+1 N 1 for i in range(N+1) [ float("inf") for j in range(N+1) ] e=[  [ float("inf") for j in range(N+1) ]  for i in range(N+1) ] e [  [ float("inf") for j in range(N+1) ]  for i in range(N+1) ] for i in range(1,N+1):
    for j in range(i,N+1):
        if i==j:
            e[i][j]=0
            e[j][i]=0
        elif d[i][j]<=L:
            e[i][j]=1
            e[j][i]=1 i range(1,N+1) range 1 N+1 N 1 for j in range(i,N+1):
        if i==j:
            e[i][j]=0
            e[j][i]=0
        elif d[i][j]<=L:
            e[i][j]=1
            e[j][i]=1 j range(i,N+1) range i N+1 N 1 if i==j:
            e[i][j]=0
            e[j][i]=0
        elif d[i][j]<=L:
            e[i][j]=1
            e[j][i]=1 i==j i j e[i][j]=0 e[i][j] [i] e i j 0 e[j][i]=0 e[j][i] [j] e j i 0 elif d[i][j]<=L:
            e[i][j]=1
            e[j][i]=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 e[j][i]=1 e[j][i] [j] e j i 1 for k in range(1,N+1):
	for i in range(1,N+1):
		for j in range(1,N+1):
			e[i][j]=min(e[i][j], e[i][k]+e[k][j]) k range(1,N+1) range 1 N+1 N 1 for i in range(1,N+1):
		for j in range(1,N+1):
			e[i][j]=min(e[i][j], e[i][k]+e[k][j]) i range(1,N+1) range 1 N+1 N 1 for j in range(1,N+1):
			e[i][j]=min(e[i][j], e[i][k]+e[k][j]) j range(1,N+1) range 1 N+1 N 1 e[i][j]=min(e[i][j], e[i][k]+e[k][j]) e[i][j] [i] e i j min(e[i][j], e[i][k]+e[k][j]) min e[i][j] [i] e i j e[i][k]+e[k][j] e[i][k] [i] e i k e[k][j] [k] e k j Q=input() Q input() input for _ in range(Q):
    s,t=map(int, sys.stdin.readline().split())
    if e[s][t]==float("inf"):
        print -1
    else:
        print e[s][t]-1 _ range(Q) range Q s,t=map(int, sys.stdin.readline().split()) s map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split t if e[s][t]==float("inf"):
        print -1
    else:
        print e[s][t]-1 e[s][t]==float("inf") e[s][t] [s] e s t float("inf") float "inf" print -1 print 1 print e[s][t]-1 e[s][t] [s] e s t 1 a,b,c=map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) a N,M,L=map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) N t=map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) t e=[  [ float("inf") for j in range(N+1) ]  for i in range(N+1) ] [  [ float("inf") for j in range(N+1) ]  for i in range(N+1) ] e L=map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) L c=map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) c Q=input() input() Q M,L=map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) M b,c=map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) b s,t=map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) s d=[  [ float("inf") for j in range(N+1) ]  for i in range(N+1) ] [  [ float("inf") for j in range(N+1) ]  for i in range(N+1) ] d
import sys

N,M,L=map(int, sys.stdin.readline().split())

d=[  [ float("inf") for j in range(N+1) ]  for i in range(N+1) ]

for _ in range(M):
    a,b,c=map(int, sys.stdin.readline().split())
    d[a][b]=c
    d[b][a]=c
    d[a][a]=0
    d[b][b]=0

for k in range(1,N+1):
	for i in range(1,N+1):
		for j in range(1,N+1):
			d[i][j]=min(d[i][j], d[i][k]+d[k][j])

e=[  [ float("inf") for j in range(N+1) ]  for i in range(N+1) ]
for i in range(1,N+1):
    for j in range(i,N+1):
        if i==j:
            e[i][j]=0
            e[j][i]=0
        elif d[i][j]<=L:
            e[i][j]=1
            e[j][i]=1

for k in range(1,N+1):
	for i in range(1,N+1):
		for j in range(1,N+1):
			e[i][j]=min(e[i][j], e[i][k]+e[k][j])


Q=input()
for _ in range(Q):
    s,t=map(int, sys.stdin.readline().split())
    if e[s][t]==float("inf"):
        print -1
    else:
        print e[s][t]-1
