def warshall_floyd(v_count: int, matrix: list) -> list:
    """ ワーシャルフロイド
    v_count: 頂点数
    matrix: 隣接行列(到達不能はfloat("inf"))
    """
    for i in range(v_count):
        for j, c2 in enumerate(row[i] for row in matrix):
            for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3
    return matrix


INF = 10 ** 16
n, m, l = map(int, input().split())
mat = [[INF] * n for _ in range(n)]
for i in range(n):
    mat[i][i] = 0
for _ in range(m):
    a, b, c = map(int, input().split())
    mat[a - 1][b - 1] = c
    mat[b - 1][a - 1] = c
mat = warshall_floyd(n, mat)
fuel_mat = [[INF] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if i == j:
            fuel_mat[i][j] = 0
        elif mat[i][j] <= l:
            fuel_mat[i][j] = 1
fuel_mat = warshall_floyd(n, fuel_mat)
q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    d = fuel_mat[s - 1][t - 1]
    if d == INF:
        print(-1)
    else:
        print(d - 1) def warshall_floyd(v_count: int, matrix: list) -> list:
    """ ワーシャルフロイド
    v_count: 頂点数
    matrix: 隣接行列(到達不能はfloat("inf"))
    """
    for i in range(v_count):
        for j, c2 in enumerate(row[i] for row in matrix):
            for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3
    return matrix warshall_floyd """ ワーシャルフロイド
    v_count: 頂点数
    matrix: 隣接行列(到達不能はfloat("inf"))
    """ for i in range(v_count):
        for j, c2 in enumerate(row[i] for row in matrix):
            for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3
     i range(v_count) range v_count for j, c2 in enumerate(row[i] for row in matrix):
            for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3
     j c2 enumerate(row[i] for row in matrix) enumerate row[i] row i for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3
     k (c1, c3) c1 c3 enumerate(zip(matrix[j], matrix[i])) enumerate zip(matrix[j], matrix[i]) zip matrix[j] matrix j matrix[i] matrix i if c1 > c2+c3:
                    matrix[j][k] = c2+c3
     c1 > c2+c3 c1 c2+c3 c2 c3 matrix[j][k] = c2+c3 matrix[j][k] [j] matrix j k c2+c3 c2 c3 return matrix matrix v_count: int v_count matrix: list matrix INF = 10 ** 16 INF 10 ** 16 10 16 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 mat = [[INF] * n for _ in range(n)] mat [[INF] * n for _ in range(n)] for i in range(n):
    mat[i][i] = 0 i range(n) range n mat[i][i] = 0 mat[i][i] [i] mat i i 0 for _ in range(m):
    a, b, c = map(int, input().split())
    mat[a - 1][b - 1] = c
    mat[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 mat[a - 1][b - 1] = c mat[a - 1][b - 1] [a - 1] mat a - 1 a 1 b - 1 b 1 c mat[b - 1][a - 1] = c mat[b - 1][a - 1] [b - 1] mat b - 1 b 1 a - 1 a 1 c mat = warshall_floyd(n, mat) mat warshall_floyd(n, mat) warshall_floyd n mat [INF] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [INF] * n [INF] INF n fuel_mat = [[INF] * n for _ in range(n)] fuel_mat [[INF] * n for _ in range(n)] for i in range(n):
    for j in range(n):
        if i == j:
            fuel_mat[i][j] = 0
        elif mat[i][j] <= l:
            fuel_mat[i][j] = 1 i range(n) range n for j in range(n):
        if i == j:
            fuel_mat[i][j] = 0
        elif mat[i][j] <= l:
            fuel_mat[i][j] = 1 j range(n) range n if i == j:
            fuel_mat[i][j] = 0
        elif mat[i][j] <= l:
            fuel_mat[i][j] = 1 i == j i j fuel_mat[i][j] = 0 fuel_mat[i][j] [i] fuel_mat i j 0 elif mat[i][j] <= l:
            fuel_mat[i][j] = 1 mat[i][j] <= l mat[i][j] [i] mat i j l fuel_mat[i][j] = 1 fuel_mat[i][j] [i] fuel_mat i j 1 fuel_mat = warshall_floyd(n, fuel_mat) fuel_mat warshall_floyd(n, fuel_mat) warshall_floyd n fuel_mat q = int(input()) q int(input()) int input() input for _ in range(q):
    s, t = map(int, input().split())
    d = fuel_mat[s - 1][t - 1]
    if d == INF:
        print(-1)
    else:
        print(d - 1) _ range(q) range q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t d = fuel_mat[s - 1][t - 1] d fuel_mat[s - 1][t - 1] [s - 1] fuel_mat s - 1 s 1 t - 1 t 1 if d == INF:
        print(-1)
    else:
        print(d - 1) d == INF d INF print(-1) print -1 print(d - 1) print d - 1 d 1 d = fuel_mat[s - 1][t - 1] fuel_mat[s - 1][t - 1] d t = map(int, input().split()) map(int, input().split()) t c = map(int, input().split()) map(int, input().split()) c INF = 10 ** 16 10 ** 16 INF b, c = map(int, input().split()) map(int, input().split()) b mat = [[INF] * n for _ in range(n)] [[INF] * n for _ in range(n)] mat fuel_mat = [[INF] * n for _ in range(n)] [[INF] * n for _ in range(n)] fuel_mat s, t = map(int, input().split()) map(int, input().split()) s def warshall_floyd(v_count: int, matrix: list) -> list:
    """ ワーシャルフロイド
    v_count: 頂点数
    matrix: 隣接行列(到達不能はfloat("inf"))
    """
    for i in range(v_count):
        for j, c2 in enumerate(row[i] for row in matrix):
            for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3
    return matrix def warshall_floyd(v_count: int, matrix: list) -> list:
    """ ワーシャルフロイド
    v_count: 頂点数
    matrix: 隣接行列(到達不能はfloat("inf"))
    """
    for i in range(v_count):
        for j, c2 in enumerate(row[i] for row in matrix):
            for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3
    return matrix warshall_floyd mat = warshall_floyd(n, mat) warshall_floyd(n, mat) mat n, m, l = map(int, input().split()) map(int, input().split()) n q = int(input()) int(input()) q m, l = map(int, input().split()) map(int, input().split()) m l = map(int, input().split()) map(int, input().split()) l a, b, c = map(int, input().split()) map(int, input().split()) a fuel_mat = warshall_floyd(n, fuel_mat) warshall_floyd(n, fuel_mat) fuel_mat
def warshall_floyd(v_count: int, matrix: list) -> list:
    """ ワーシャルフロイド
    v_count: 頂点数
    matrix: 隣接行列(到達不能はfloat("inf"))
    """
    for i in range(v_count):
        for j, c2 in enumerate(row[i] for row in matrix):
            for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3
    return matrix


INF = 10 ** 16
n, m, l = map(int, input().split())
mat = [[INF] * n for _ in range(n)]
for i in range(n):
    mat[i][i] = 0
for _ in range(m):
    a, b, c = map(int, input().split())
    mat[a - 1][b - 1] = c
    mat[b - 1][a - 1] = c
mat = warshall_floyd(n, mat)
fuel_mat = [[INF] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if i == j:
            fuel_mat[i][j] = 0
        elif mat[i][j] <= l:
            fuel_mat[i][j] = 1
fuel_mat = warshall_floyd(n, fuel_mat)
q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    d = fuel_mat[s - 1][t - 1]
    if d == INF:
        print(-1)
    else:
        print(d - 1)
