import sys
input = sys.stdin.readline

n, m, l = map(int, input().split())
INF = float("inf")

def warshall_floyd(d, n):
    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

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

d2 = [[INF] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if d[i][j] <= l:
            d2[i][j] = 1
    d2[i][i] = 0
d2 = warshall_floyd(d2, n)

q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    res = d2[s - 1][t - 1]
    print(-1 if res == INF else res - 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 INF = float("inf") INF float("inf") float "inf" def warshall_floyd(d, n):
    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 warshall_floyd 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 n 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)] 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 for i in range(m):
    a, b, c = map(int, input().split())
    d[a - 1][b - 1] = c
    d[b - 1][a - 1] = c i 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 d = warshall_floyd(d, n) d warshall_floyd(d, n) warshall_floyd d 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 i in range(n):
    for j in range(n):
        if d[i][j] <= l:
            d2[i][j] = 1
    d2[i][i] = 0 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 d2[i][i] = 0 d2[i][i] [i] d2 i i 0 d2 = warshall_floyd(d2, n) d2 warshall_floyd(d2, n) warshall_floyd d2 n q = int(input()) q int(input()) int input() input for _ in range(q):
    s, t = map(int, input().split())
    res = d2[s - 1][t - 1]
    print(-1 if res == INF else res - 1) _ range(q) range q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t res = d2[s - 1][t - 1] res d2[s - 1][t - 1] [s - 1] d2 s - 1 s 1 t - 1 t 1 print(-1 if res == INF else res - 1) print -1 if res == INF else res - 1 res == INF res INF -1 res - 1 res 1 m, l = map(int, input().split()) map(int, input().split()) m c = map(int, input().split()) map(int, input().split()) c q = int(input()) int(input()) q 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 res = d2[s - 1][t - 1] d2[s - 1][t - 1] res d = warshall_floyd(d, n) warshall_floyd(d, n) d def warshall_floyd(d, n):
    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 warshall_floyd(d, n):
    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 warshall_floyd INF = float("inf") float("inf") INF s, t = map(int, input().split()) map(int, input().split()) s a, b, c = map(int, input().split()) map(int, input().split()) a n, m, l = map(int, input().split()) map(int, input().split()) n l = map(int, input().split()) map(int, input().split()) l d2 = [[INF] * n for _ in range(n)] [[INF] * n for _ in range(n)] d2 d2 = warshall_floyd(d2, n) warshall_floyd(d2, n) d2 input = sys.stdin.readline sys.stdin.readline input t = map(int, input().split()) map(int, input().split()) t
import sys
input = sys.stdin.readline

n, m, l = map(int, input().split())
INF = float("inf")

def warshall_floyd(d, n):
    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

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

d2 = [[INF] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if d[i][j] <= l:
            d2[i][j] = 1
    d2[i][i] = 0
d2 = warshall_floyd(d2, n)

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