def warshal(data):

    for k in range(n):

        for i in range(n):

            for j in range(n):

                data[i][j]=min(data[i][j],data[i][k]+data[k][j])

    return data

n,m,l=list(map(int,input().split()))

inf=float("inf")

data=[[inf]*n for i in range(n)]

for i in range(m):

    a,b,c=list(map(int,input().split()))

    data[a-1][b-1]=c

    data[b-1][a-1]=c

for i in range(n):

    data[i][i]=0

data=warshal(data)

for i in range(n):

    for j in range(n):

        if data[i][j]<=l:

            data[i][j]=1

        else:

            data[i][j]=inf

for i in range(n):

    data[i][i]=0

data=warshal(data)

q=int(eval(input()))

st=[]

for i in range(q):

    s,t=list(map(int,input().split()))

    st.append([s-1,t-1])

for s,t in st:

    if data[s][t]==inf:

        print((-1))

    else:

        print((data[s][t]-1))
import sys

input=sys.stdin.readline



def Warshall_Floyd(N,DIST):

    for k in range(N):

        for i in range(N):

            for j in range(N):

                DIST[i][j]=min(DIST[i][j],DIST[i][k]+DIST[k][j])

    return DIST



N,M,L=list(map(int,input().split()))



ABC=[list(map(int,input().split())) for i in range(M)]



Q=int(eval(input()))



st=[list(map(int,input().split())) for i in range(Q)]



inf=L+1

dist=[[inf]*N for i in range(N)]

for i in range(N):

    dist[i][i]=0

for A,B,C in ABC:

    dist[A-1][B-1]=min(dist[A-1][B-1],C)

    dist[B-1][A-1]=min(dist[B-1][A-1],C)



dist=Warshall_Floyd(N,dist)

dist_2=[[N+1]*N for i in range(N)]



for i in range(N):

    for j in range(N):

        if dist[i][j]<=L:

            dist_2[i][j]=1

            

for i in range(N):

    dist_2[i][i]=0



dist_2=Warshall_Floyd(N,dist_2)



for s,t in st:

    if dist_2[s-1][t-1]==N+1:

        print((-1))

    else:

        print((dist_2[s-1][t-1]-1))
def warshal(data):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                data[i][j] = min(data[i][j], data[i][k] + data[k][j])
    return data


n, m, l = list(map(int, input().split()))
inf = float("inf")
data = [[inf] * n for i in range(n)]
for i in range(m):
    a, b, c = list(map(int, input().split()))
    data[a - 1][b - 1] = c
    data[b - 1][a - 1] = c
for i in range(n):
    data[i][i] = 0
data = warshal(data)
for i in range(n):
    for j in range(n):
        if data[i][j] <= l:
            data[i][j] = 1
        else:
            data[i][j] = inf
for i in range(n):
    data[i][i] = 0
data = warshal(data)
q = int(eval(input()))
st = []
for i in range(q):
    s, t = list(map(int, input().split()))
    st.append([s - 1, t - 1])
for s, t in st:
    if data[s][t] == inf:
        print((-1))
    else:
        print((data[s][t] - 1))

import sys

input = sys.stdin.readline


def Warshall_Floyd(N, DIST):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                DIST[i][j] = min(DIST[i][j], DIST[i][k] + DIST[k][j])
    return DIST


N, M, L = list(map(int, input().split()))
ABC = [list(map(int, input().split())) for i in range(M)]
Q = int(eval(input()))
st = [list(map(int, input().split())) for i in range(Q)]
inf = L + 1
dist = [[inf] * N for i in range(N)]
for i in range(N):
    dist[i][i] = 0
for A, B, C in ABC:
    dist[A - 1][B - 1] = min(dist[A - 1][B - 1], C)
    dist[B - 1][A - 1] = min(dist[B - 1][A - 1], C)
dist = Warshall_Floyd(N, dist)
dist_2 = [[N + 1] * N for i in range(N)]
for i in range(N):
    for j in range(N):
        if dist[i][j] <= L:
            dist_2[i][j] = 1
for i in range(N):
    dist_2[i][i] = 0
dist_2 = Warshall_Floyd(N, dist_2)
for s, t in st:
    if dist_2[s - 1][t - 1] == N + 1:
        print((-1))
    else:
        print((dist_2[s - 1][t - 1] - 1))

-def warshal(data): -    for k in range(n): -        for i in range(n): -            for j in range(n): -                data[i][j] = min(data[i][j], data[i][k] + data[k][j]) -    return data +import sys + +input = sys.stdin.readline -n, m, l = list(map(int, input().split())) -inf = float("inf") -data = [[inf] * n for i in range(n)] -for i in range(m): -    a, b, c = list(map(int, input().split())) -    data[a - 1][b - 1] = c -    data[b - 1][a - 1] = c -for i in range(n): -    data[i][i] = 0 -data = warshal(data) -for i in range(n): -    for j in range(n): -        if data[i][j] <= l: -            data[i][j] = 1 -        else: -            data[i][j] = inf -for i in range(n): -    data[i][i] = 0 -data = warshal(data) -q = int(eval(input())) -st = [] -for i in range(q): -    s, t = list(map(int, input().split())) -    st.append([s - 1, t - 1]) +def Warshall_Floyd(N, DIST): +    for k in range(N): +        for i in range(N): +            for j in range(N): +                DIST[i][j] = min(DIST[i][j], DIST[i][k] + DIST[k][j]) +    return DIST + + +N, M, L = list(map(int, input().split())) +ABC = [list(map(int, input().split())) for i in range(M)] +Q = int(eval(input())) +st = [list(map(int, input().split())) for i in range(Q)] +inf = L + 1 +dist = [[inf] * N for i in range(N)] +for i in range(N): +    dist[i][i] = 0 +for A, B, C in ABC: +    dist[A - 1][B - 1] = min(dist[A - 1][B - 1], C) +    dist[B - 1][A - 1] = min(dist[B - 1][A - 1], C) +dist = Warshall_Floyd(N, dist) +dist_2 = [[N + 1] * N for i in range(N)] +for i in range(N): +    for j in range(N): +        if dist[i][j] <= L: +            dist_2[i][j] = 1 +for i in range(N): +    dist_2[i][i] = 0 +dist_2 = Warshall_Floyd(N, dist_2) -    if data[s][t] == inf: +    if dist_2[s - 1][t - 1] == N + 1: -        print((data[s][t] - 1)) +        print((dist_2[s - 1][t - 1] - 1))