def warshall_floyd(G):
    import copy
    ret = copy.deepcopy(G)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                ret[i][j] = min(ret[i][j], ret[i][k] + ret[k][j])
    return ret


INF = 10 ** 10
N, M, L = map(int, input().split())

G = [[INF] * N for _ in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    G[A - 1][B - 1], G[B - 1][A - 1] = C, C

MinG = warshall_floyd(G)
GL = [[1 if MinG[i][j] <= L else INF for j in range(N)] for i in range(N)]
MinGL = warshall_floyd(GL)

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    print(-1 if MinGL[s - 1][t - 1] == INF else MinGL[s - 1][t - 1] - 1) def warshall_floyd(G):
    import copy
    ret = copy.deepcopy(G)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                ret[i][j] = min(ret[i][j], ret[i][k] + ret[k][j])
    return ret warshall_floyd import copy copy ret = copy.deepcopy(G) ret copy.deepcopy(G) copy.deepcopy copy deepcopy G for k in range(N):
        for i in range(N):
            for j in range(N):
                ret[i][j] = min(ret[i][j], ret[i][k] + ret[k][j])
     k range(N) range N for i in range(N):
            for j in range(N):
                ret[i][j] = min(ret[i][j], ret[i][k] + ret[k][j])
     i range(N) range N for j in range(N):
                ret[i][j] = min(ret[i][j], ret[i][k] + ret[k][j])
     j range(N) range N ret[i][j] = min(ret[i][j], ret[i][k] + ret[k][j]) ret[i][j] [i] ret i j min(ret[i][j], ret[i][k] + ret[k][j]) min ret[i][j] [i] ret i j ret[i][k] + ret[k][j] ret[i][k] [i] ret i k ret[k][j] [k] ret k j return ret ret G G INF = 10 ** 10 INF 10 ** 10 10 10 N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L [INF] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF] * N [INF] INF N G = [[INF] * N for _ in range(N)] G [[INF] * N for _ in range(N)] for i in range(M):
    A, B, C = map(int, input().split())
    G[A - 1][B - 1], G[B - 1][A - 1] = C, 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 G[A - 1][B - 1], G[B - 1][A - 1] = C, C G[A - 1][B - 1] [A - 1] G A - 1 A 1 B - 1 B 1 C G[B - 1][A - 1] [B - 1] G B - 1 B 1 A - 1 A 1 C MinG = warshall_floyd(G) MinG warshall_floyd(G) warshall_floyd G [1 if MinG[i][j] <= L else INF for j in range(N)] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [1 if MinG[i][j] <= L else INF for j in range(N)] GL = [[1 if MinG[i][j] <= L else INF for j in range(N)] for i in range(N)] GL [[1 if MinG[i][j] <= L else INF for j in range(N)] for i in range(N)] MinGL = warshall_floyd(GL) MinGL warshall_floyd(GL) warshall_floyd GL Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s, t = map(int, input().split())
    print(-1 if MinGL[s - 1][t - 1] == INF else MinGL[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 print(-1 if MinGL[s - 1][t - 1] == INF else MinGL[s - 1][t - 1] - 1) print -1 if MinGL[s - 1][t - 1] == INF else MinGL[s - 1][t - 1] - 1 MinGL[s - 1][t - 1] == INF MinGL[s - 1][t - 1] [s - 1] MinGL s - 1 s 1 t - 1 t 1 INF -1 MinGL[s - 1][t - 1] - 1 MinGL[s - 1][t - 1] [s - 1] MinGL s - 1 s 1 t - 1 t 1 1 def warshall_floyd(G):
    import copy
    ret = copy.deepcopy(G)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                ret[i][j] = min(ret[i][j], ret[i][k] + ret[k][j])
    return ret def warshall_floyd(G):
    import copy
    ret = copy.deepcopy(G)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                ret[i][j] = min(ret[i][j], ret[i][k] + ret[k][j])
    return ret warshall_floyd N, M, L = map(int, input().split()) map(int, input().split()) N GL = [[1 if MinG[i][j] <= L else INF for j in range(N)] for i in range(N)] [[1 if MinG[i][j] <= L else INF for j in range(N)] for i in range(N)] GL G = [[INF] * N for _ in range(N)] [[INF] * N for _ in range(N)] G Q = int(input()) int(input()) Q A, B, C = map(int, input().split()) map(int, input().split()) A INF = 10 ** 10 10 ** 10 INF M, L = map(int, input().split()) map(int, input().split()) M t = map(int, input().split()) map(int, input().split()) t L = map(int, input().split()) map(int, input().split()) L MinG = warshall_floyd(G) warshall_floyd(G) MinG MinGL = warshall_floyd(GL) warshall_floyd(GL) MinGL C = map(int, input().split()) map(int, input().split()) C s, t = map(int, input().split()) map(int, input().split()) s B, C = map(int, input().split()) map(int, input().split()) B
def warshall_floyd(G):
    import copy
    ret = copy.deepcopy(G)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                ret[i][j] = min(ret[i][j], ret[i][k] + ret[k][j])
    return ret


INF = 10 ** 10
N, M, L = map(int, input().split())

G = [[INF] * N for _ in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    G[A - 1][B - 1], G[B - 1][A - 1] = C, C

MinG = warshall_floyd(G)
GL = [[1 if MinG[i][j] <= L else INF for j in range(N)] for i in range(N)]
MinGL = warshall_floyd(GL)

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