n,m,L=map(int,input().split(' '))

inf=10**10

d=[[inf]*n for _ in range(n)]
for _ in range(m):
    a,b,c=map(int,input().split(' '))
    d[a-1][b-1]=c
    d[b-1][a-1]=c

for k in range(n):
    for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
                
dl=[[inf]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if d[i][j] <= L:
            dl[i][j]=1

for k in range(n):
    for i in range(n):
        for j in range(n):
            if dl[i][j] > dl[i][k] + dl[k][j]:
                dl[i][j] = dl[i][k] + dl[k][j]

q=int(input())
for _ in range(q):
    s,t = map(int,input().split(' '))
    if dl[s-1][t-1]==inf:
        print(-1)
    else:
        print(dl[s-1][t-1]-1) n,m,L=map(int,input().split(' ')) n map(int,input().split(' ')) map int input().split(' ') ().split () input split ' ' m L inf=10**10 inf 10**10 10 10 [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)] for _ in range(m):
    a,b,c=map(int,input().split(' '))
    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 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 k in range(n):
    for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
                 k range(n) range n for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
                 i range(n) range n for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
                 j range(n) range n if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
                 d[i][j] > d[i][k] + d[k][j] 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 d[i][j] = d[i][k] + d[k][j] 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 [inf]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [inf]*n [inf] inf n dl=[[inf]*n for _ in range(n)] dl [[inf]*n for _ in range(n)] for i in range(n):
    for j in range(n):
        if d[i][j] <= L:
            dl[i][j]=1 i range(n) range n for j in range(n):
        if d[i][j] <= L:
            dl[i][j]=1 j range(n) range n if d[i][j] <= L:
            dl[i][j]=1 d[i][j] <= L d[i][j] [i] d i j L dl[i][j]=1 dl[i][j] [i] dl i j 1 for k in range(n):
    for i in range(n):
        for j in range(n):
            if dl[i][j] > dl[i][k] + dl[k][j]:
                dl[i][j] = dl[i][k] + dl[k][j] k range(n) range n for i in range(n):
        for j in range(n):
            if dl[i][j] > dl[i][k] + dl[k][j]:
                dl[i][j] = dl[i][k] + dl[k][j] i range(n) range n for j in range(n):
            if dl[i][j] > dl[i][k] + dl[k][j]:
                dl[i][j] = dl[i][k] + dl[k][j] j range(n) range n if dl[i][j] > dl[i][k] + dl[k][j]:
                dl[i][j] = dl[i][k] + dl[k][j] dl[i][j] > dl[i][k] + dl[k][j] dl[i][j] [i] dl i j dl[i][k] + dl[k][j] dl[i][k] [i] dl i k dl[k][j] [k] dl k j dl[i][j] = dl[i][k] + dl[k][j] dl[i][j] [i] dl i j dl[i][k] + dl[k][j] dl[i][k] [i] dl i k dl[k][j] [k] dl k j q=int(input()) q int(input()) int input() input for _ in range(q):
    s,t = map(int,input().split(' '))
    if dl[s-1][t-1]==inf:
        print(-1)
    else:
        print(dl[s-1][t-1]-1) _ range(q) range q s,t = map(int,input().split(' ')) s map(int,input().split(' ')) map int input().split(' ') ().split () input split ' ' t if dl[s-1][t-1]==inf:
        print(-1)
    else:
        print(dl[s-1][t-1]-1) dl[s-1][t-1]==inf dl[s-1][t-1] [s-1] dl s-1 s 1 t-1 t 1 inf print(-1) print -1 print(dl[s-1][t-1]-1) print dl[s-1][t-1]-1 dl[s-1][t-1] [s-1] dl s-1 s 1 t-1 t 1 1 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 b,c=map(int,input().split(' ')) map(int,input().split(' ')) b c=map(int,input().split(' ')) map(int,input().split(' ')) c dl=[[inf]*n for _ in range(n)] [[inf]*n for _ in range(n)] dl q=int(input()) int(input()) q L=map(int,input().split(' ')) map(int,input().split(' ')) L n,m,L=map(int,input().split(' ')) map(int,input().split(' ')) n t = map(int,input().split(' ')) map(int,input().split(' ')) t inf=10**10 10**10 inf m,L=map(int,input().split(' ')) map(int,input().split(' ')) m
n,m,L=map(int,input().split(' '))

inf=10**10

d=[[inf]*n for _ in range(n)]
for _ in range(m):
    a,b,c=map(int,input().split(' '))
    d[a-1][b-1]=c
    d[b-1][a-1]=c

for k in range(n):
    for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
                
dl=[[inf]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if d[i][j] <= L:
            dl[i][j]=1

for k in range(n):
    for i in range(n):
        for j in range(n):
            if dl[i][j] > dl[i][k] + dl[k][j]:
                dl[i][j] = dl[i][k] + dl[k][j]

q=int(input())
for _ in range(q):
    s,t = map(int,input().split(' '))
    if dl[s-1][t-1]==inf:
        print(-1)
    else:
        print(dl[s-1][t-1]-1)