# import sys
# input = sys.stdin.readline

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

def warshall_floyd(dp):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dp[i][j] = min(dp[i][j] , dp[i][k] + dp[k][j])
    return dp

dp = [[float('inf')]*n for _ in range(n)]

for _ in range(m):
    a, b, c = map(int,input().split())
    dp[a-1][b-1] = dp[b-1][a-1] = c

for i in range(n):
    dp[i][i] = 0

dp = warshall_floyd(dp)

dp2 = [[float('inf')]*n for _ in range(n)]

for i in range(n):
    for j in range(n):
        if dp[i][j] <= l:
            dp2[i][j] = 1
    dp2[i][i] = 0
dp2 = warshall_floyd(dp2)

q = int(input())

ans = [0]*q
for i in range(q):
    s, t = map(int,input().split())
    tmp = dp2[s-1][t-1]
    ans[i] = -1 if tmp == float('inf') else tmp - 1

print(*ans, sep='\n') n, m, l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l def warshall_floyd(dp):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dp[i][j] = min(dp[i][j] , dp[i][k] + dp[k][j])
    return dp warshall_floyd for k in range(n):
        for i in range(n):
            for j in range(n):
                dp[i][j] = min(dp[i][j] , dp[i][k] + dp[k][j])
     k range(n) range n for i in range(n):
            for j in range(n):
                dp[i][j] = min(dp[i][j] , dp[i][k] + dp[k][j])
     i range(n) range n for j in range(n):
                dp[i][j] = min(dp[i][j] , dp[i][k] + dp[k][j])
     j range(n) range n dp[i][j] = min(dp[i][j] , dp[i][k] + dp[k][j]) dp[i][j] [i] dp i j min(dp[i][j] , dp[i][k] + dp[k][j]) min dp[i][j] [i] dp i j dp[i][k] + dp[k][j] dp[i][k] [i] dp i k dp[k][j] [k] dp k j return dp dp dp dp [float('inf')]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [float('inf')]*n [float('inf')] float('inf') float 'inf' n dp = [[float('inf')]*n for _ in range(n)] dp [[float('inf')]*n for _ in range(n)] for _ in range(m):
    a, b, c = map(int,input().split())
    dp[a-1][b-1] = dp[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 dp[a-1][b-1] = dp[b-1][a-1] = c dp[a-1][b-1] [a-1] dp a-1 a 1 b-1 b 1 c = dp[b-1][a-1] = c dp[b-1][a-1] [b-1] dp b-1 b 1 a-1 a 1 c for i in range(n):
    dp[i][i] = 0 i range(n) range n dp[i][i] = 0 dp[i][i] [i] dp i i 0 dp = warshall_floyd(dp) dp warshall_floyd(dp) warshall_floyd dp [float('inf')]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [float('inf')]*n [float('inf')] float('inf') float 'inf' n dp2 = [[float('inf')]*n for _ in range(n)] dp2 [[float('inf')]*n for _ in range(n)] for i in range(n):
    for j in range(n):
        if dp[i][j] <= l:
            dp2[i][j] = 1
    dp2[i][i] = 0 i range(n) range n for j in range(n):
        if dp[i][j] <= l:
            dp2[i][j] = 1
     j range(n) range n if dp[i][j] <= l:
            dp2[i][j] = 1
     dp[i][j] <= l dp[i][j] [i] dp i j l dp2[i][j] = 1 dp2[i][j] [i] dp2 i j 1 dp2[i][i] = 0 dp2[i][i] [i] dp2 i i 0 dp2 = warshall_floyd(dp2) dp2 warshall_floyd(dp2) warshall_floyd dp2 q = int(input()) q int(input()) int input() input ans = [0]*q ans [0]*q [0] 0 q for i in range(q):
    s, t = map(int,input().split())
    tmp = dp2[s-1][t-1]
    ans[i] = -1 if tmp == float('inf') else tmp - 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 tmp = dp2[s-1][t-1] tmp dp2[s-1][t-1] [s-1] dp2 s-1 s 1 t-1 t 1 ans[i] = -1 if tmp == float('inf') else tmp - 1 ans[i] ans i -1 if tmp == float('inf') else tmp - 1 tmp == float('inf') tmp float('inf') float 'inf' -1 tmp - 1 tmp 1 print(*ans, sep='\n') print *ans ans sep='\n' sep '\n' dp = warshall_floyd(dp) warshall_floyd(dp) dp b, c = map(int,input().split()) map(int,input().split()) b m, l = map(int, input().split()) map(int, input().split()) m c = map(int,input().split()) map(int,input().split()) c dp = [[float('inf')]*n for _ in range(n)] [[float('inf')]*n for _ in range(n)] dp t = map(int,input().split()) map(int,input().split()) t l = map(int, input().split()) map(int, input().split()) l dp2 = [[float('inf')]*n for _ in range(n)] [[float('inf')]*n for _ in range(n)] dp2 q = int(input()) int(input()) q tmp = dp2[s-1][t-1] dp2[s-1][t-1] tmp def warshall_floyd(dp):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dp[i][j] = min(dp[i][j] , dp[i][k] + dp[k][j])
    return dp def warshall_floyd(dp):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dp[i][j] = min(dp[i][j] , dp[i][k] + dp[k][j])
    return dp warshall_floyd a, b, c = map(int,input().split()) map(int,input().split()) a n, m, l = map(int, input().split()) map(int, input().split()) n dp2 = warshall_floyd(dp2) warshall_floyd(dp2) dp2 ans = [0]*q [0]*q ans s, t = map(int,input().split()) map(int,input().split()) s
# import sys
# input = sys.stdin.readline

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

def warshall_floyd(dp):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dp[i][j] = min(dp[i][j] , dp[i][k] + dp[k][j])
    return dp

dp = [[float('inf')]*n for _ in range(n)]

for _ in range(m):
    a, b, c = map(int,input().split())
    dp[a-1][b-1] = dp[b-1][a-1] = c

for i in range(n):
    dp[i][i] = 0

dp = warshall_floyd(dp)

dp2 = [[float('inf')]*n for _ in range(n)]

for i in range(n):
    for j in range(n):
        if dp[i][j] <= l:
            dp2[i][j] = 1
    dp2[i][i] = 0
dp2 = warshall_floyd(dp2)

q = int(input())

ans = [0]*q
for i in range(q):
    s, t = map(int,input().split())
    tmp = dp2[s-1][t-1]
    ans[i] = -1 if tmp == float('inf') else tmp - 1

print(*ans, sep='\n')
