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

def war(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=(L+1)*N
d=[[INF]*N for _ in range(N)]
d2=[[INF]*N for _ in range(N)]

for _ in range(M):
    A,B,C=map(int,input().split())
    if C>L:
        continue
    d[A-1][B-1]=C
    d[B-1][A-1]=C

for i in range(N):
    d[i][i]=0

d=war(d)

for i in range(N):
    for j in range(N):
        if d[i][j]<=L:
            d2[i][j]=1
for i in range(N):
    d2[i][i]=0
d2=war(d2)
#print(d)
#print(d2)
Q=int(input())
for i in range(Q):
    s,t=map(int,input().split())
    print(d2[s-1][t-1] %INF -1) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N,M,L=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L def war(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 war 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=(L+1)*N INF (L+1)*N L+1 L 1 N [INF]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF]*N [INF] INF N d=[[INF]*N for _ in range(N)] d [[INF]*N for _ in range(N)] [INF]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF]*N [INF] INF N d2=[[INF]*N for _ in range(N)] d2 [[INF]*N for _ in range(N)] for _ in range(M):
    A,B,C=map(int,input().split())
    if C>L:
        continue
    d[A-1][B-1]=C
    d[B-1][A-1]=C _ range(M) range M A,B,C=map(int,input().split()) A map(int,input().split()) map int input().split() ().split () input split B C if C>L:
        continue
     C>L C L continue d[A-1][B-1]=C d[A-1][B-1] [A-1] d A-1 A 1 B-1 B 1 C d[B-1][A-1]=C d[B-1][A-1] [B-1] d B-1 B 1 A-1 A 1 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 d=war(d) d war(d) war d for i in range(N):
    for j in range(N):
        if d[i][j]<=L:
            d2[i][j]=1 i range(N) range N 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 i in range(N):
    d2[i][i]=0 i range(N) range N d2[i][i]=0 d2[i][i] [i] d2 i i 0 d2=war(d2) d2 war(d2) war d2 Q=int(input()) Q int(input()) int input() input for i in range(Q):
    s,t=map(int,input().split())
    print(d2[s-1][t-1] %INF -1) i range(Q) range Q s,t=map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t print(d2[s-1][t-1] %INF -1) print d2[s-1][t-1] %INF -1 d2[s-1][t-1] %INF d2[s-1][t-1] [s-1] d2 s-1 s 1 t-1 t 1 INF 1 d=war(d) war(d) d N,M,L=map(int,input().split()) map(int,input().split()) N Q=int(input()) int(input()) Q d2=war(d2) war(d2) d2 L=map(int,input().split()) map(int,input().split()) L M,L=map(int,input().split()) map(int,input().split()) M input = sys.stdin.readline sys.stdin.readline input def war(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 war(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 war INF=(L+1)*N (L+1)*N INF d2=[[INF]*N for _ in range(N)] [[INF]*N for _ in range(N)] d2 C=map(int,input().split()) map(int,input().split()) C t=map(int,input().split()) map(int,input().split()) t B,C=map(int,input().split()) map(int,input().split()) B s,t=map(int,input().split()) map(int,input().split()) s A,B,C=map(int,input().split()) map(int,input().split()) A d=[[INF]*N for _ in range(N)] [[INF]*N for _ in range(N)] d
import sys
input = sys.stdin.readline
N,M,L=map(int,input().split())

def war(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=(L+1)*N
d=[[INF]*N for _ in range(N)]
d2=[[INF]*N for _ in range(N)]

for _ in range(M):
    A,B,C=map(int,input().split())
    if C>L:
        continue
    d[A-1][B-1]=C
    d[B-1][A-1]=C

for i in range(N):
    d[i][i]=0

d=war(d)

for i in range(N):
    for j in range(N):
        if d[i][j]<=L:
            d2[i][j]=1
for i in range(N):
    d2[i][i]=0
d2=war(d2)
#print(d)
#print(d2)
Q=int(input())
for i in range(Q):
    s,t=map(int,input().split())
    print(d2[s-1][t-1] %INF -1)
