import sys
input = sys.stdin.readline


def dijkstra(start, matrix):
    # O(V^2)ダイクストラ
    INF = 10 ** 18
    n = len(matrix)
    used = [False] * n
    # 補給回数: 少ないほうがいい
    # 使用燃料: 少ないほうがいい
    # 補給回数が少ないほうがより嬉しい
    # dist[v] = 補給回数 * (10 ** 15) + 使用燃料
    dist = [INF] * n
    dist[start] = 0
    while True:
        v = -1
        for u in range(n):
            if not used[u] and (v == -1 or dist[u] < dist[v]):
                v = u
        if v == -1:
            break
        used[v] = True
        for nxt_v in range(n):
            tmp = merge(dist[v], matrix[v][nxt_v])
            dist[nxt_v] = min(dist[nxt_v], tmp)
    return dist

def merge(d, cost):
    div_d, mod_d = divmod(d + cost, 10 ** 15)
    if mod_d > l:
        new_d = (div_d + 1) * 10 ** 15 + cost
    else:
        new_d = d + cost
    return new_d


n, m, l = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]
q = int(input())
query = [list(map(int, input().split())) for i in range(q)]
INF = 10 ** 18

# 隣接行列
matrix = [[INF] * n for i in range(n)]
for i in range(n):
    matrix[i][i] = 0
for a, b, cost in info:
    a -= 1
    b -= 1
    if cost > l:
        continue
    matrix[a][b] = cost
    matrix[b][a] = cost

ans = [[0] * n for i in range(n)] 
for i in range(n):
    tmp = dijkstra(i, matrix)
    for j in range(n):
        ans[i][j] = tmp[j] // (10 ** 15)

for a, b in query:
    a -= 1
    b -= 1
    if ans[a][b] == 1000:
        print(-1)
    else:
        print(ans[a][b]) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def dijkstra(start, matrix):
    # O(V^2)ダイクストラ
    INF = 10 ** 18
    n = len(matrix)
    used = [False] * n
    # 補給回数: 少ないほうがいい
    # 使用燃料: 少ないほうがいい
    # 補給回数が少ないほうがより嬉しい
    # dist[v] = 補給回数 * (10 ** 15) + 使用燃料
    dist = [INF] * n
    dist[start] = 0
    while True:
        v = -1
        for u in range(n):
            if not used[u] and (v == -1 or dist[u] < dist[v]):
                v = u
        if v == -1:
            break
        used[v] = True
        for nxt_v in range(n):
            tmp = merge(dist[v], matrix[v][nxt_v])
            dist[nxt_v] = min(dist[nxt_v], tmp)
    return dist dijkstra INF = 10 ** 18 INF 10 ** 18 10 18 n = len(matrix) n len(matrix) len matrix used = [False] * n used [False] * n [False] False n dist = [INF] * n dist [INF] * n [INF] INF n dist[start] = 0 dist[start] dist start 0 while True:
        v = -1
        for u in range(n):
            if not used[u] and (v == -1 or dist[u] < dist[v]):
                v = u
        if v == -1:
            break
        used[v] = True
        for nxt_v in range(n):
            tmp = merge(dist[v], matrix[v][nxt_v])
            dist[nxt_v] = min(dist[nxt_v], tmp)
     True v = -1 v -1 for u in range(n):
            if not used[u] and (v == -1 or dist[u] < dist[v]):
                v = u
         u range(n) range n if not used[u] and (v == -1 or dist[u] < dist[v]):
                v = u
         not used[u] and (v == -1 or dist[u] < dist[v]) not used[u] used[u] used u v == -1 or dist[u] < dist[v] v == -1 v -1 dist[u] < dist[v] dist[u] dist u dist[v] dist v v = u v u if v == -1:
            break
         v == -1 v -1 break used[v] = True used[v] used v True for nxt_v in range(n):
            tmp = merge(dist[v], matrix[v][nxt_v])
            dist[nxt_v] = min(dist[nxt_v], tmp)
     nxt_v range(n) range n tmp = merge(dist[v], matrix[v][nxt_v]) tmp merge(dist[v], matrix[v][nxt_v]) merge dist[v] dist v matrix[v][nxt_v] [v] matrix v nxt_v dist[nxt_v] = min(dist[nxt_v], tmp) dist[nxt_v] dist nxt_v min(dist[nxt_v], tmp) min dist[nxt_v] dist nxt_v tmp return dist dist start start matrix matrix def merge(d, cost):
    div_d, mod_d = divmod(d + cost, 10 ** 15)
    if mod_d > l:
        new_d = (div_d + 1) * 10 ** 15 + cost
    else:
        new_d = d + cost
    return new_d merge div_d, mod_d = divmod(d + cost, 10 ** 15) div_d divmod(d + cost, 10 ** 15) divmod d + cost d cost 10 ** 15 10 15 mod_d if mod_d > l:
        new_d = (div_d + 1) * 10 ** 15 + cost
    else:
        new_d = d + cost
     mod_d > l mod_d l new_d = (div_d + 1) * 10 ** 15 + cost new_d (div_d + 1) * 10 ** 15 + cost (div_d + 1) * 10 ** 15 div_d + 1 div_d 1 10 ** 15 10 15 cost new_d = d + cost new_d d + cost d cost return new_d new_d d d cost cost n, m, l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l list(map(int, input().split())) for i in range(m) for i in range(m) i range(m) range m for i in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split info = [list(map(int, input().split())) for i in range(m)] info [list(map(int, input().split())) for i in range(m)] q = int(input()) q int(input()) int input() input list(map(int, input().split())) for i in range(q) for i in range(q) i range(q) range q for i in range(q) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split query = [list(map(int, input().split())) for i in range(q)] query [list(map(int, input().split())) for i in range(q)] INF = 10 ** 18 INF 10 ** 18 10 18 [INF] * n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [INF] * n [INF] INF n matrix = [[INF] * n for i in range(n)] matrix [[INF] * n for i in range(n)] for i in range(n):
    matrix[i][i] = 0 i range(n) range n matrix[i][i] = 0 matrix[i][i] [i] matrix i i 0 for a, b, cost in info:
    a -= 1
    b -= 1
    if cost > l:
        continue
    matrix[a][b] = cost
    matrix[b][a] = cost a b cost info a -= 1 a 1 b -= 1 b 1 if cost > l:
        continue
     cost > l cost l continue matrix[a][b] = cost matrix[a][b] [a] matrix a b cost matrix[b][a] = cost matrix[b][a] [b] matrix b a cost [0] * n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [0] * n [0] 0 n ans = [[0] * n for i in range(n)] ans [[0] * n for i in range(n)] for i in range(n):
    tmp = dijkstra(i, matrix)
    for j in range(n):
        ans[i][j] = tmp[j] // (10 ** 15) i range(n) range n tmp = dijkstra(i, matrix) tmp dijkstra(i, matrix) dijkstra i matrix for j in range(n):
        ans[i][j] = tmp[j] // (10 ** 15) j range(n) range n ans[i][j] = tmp[j] // (10 ** 15) ans[i][j] [i] ans i j tmp[j] // (10 ** 15) tmp[j] tmp j 10 ** 15 10 15 for a, b in query:
    a -= 1
    b -= 1
    if ans[a][b] == 1000:
        print(-1)
    else:
        print(ans[a][b]) a b query a -= 1 a 1 b -= 1 b 1 if ans[a][b] == 1000:
        print(-1)
    else:
        print(ans[a][b]) ans[a][b] == 1000 ans[a][b] [a] ans a b 1000 print(-1) print -1 print(ans[a][b]) print ans[a][b] [a] ans a b n, m, l = map(int, input().split()) map(int, input().split()) n b -= 1 1 b m, l = map(int, input().split()) map(int, input().split()) m l = map(int, input().split()) map(int, input().split()) l INF = 10 ** 18 10 ** 18 INF ans = [[0] * n for i in range(n)] [[0] * n for i in range(n)] ans tmp = dijkstra(i, matrix) dijkstra(i, matrix) tmp input = sys.stdin.readline sys.stdin.readline input a -= 1 1 a info = [list(map(int, input().split())) for i in range(m)] [list(map(int, input().split())) for i in range(m)] info a -= 1 1 a def merge(d, cost):
    div_d, mod_d = divmod(d + cost, 10 ** 15)
    if mod_d > l:
        new_d = (div_d + 1) * 10 ** 15 + cost
    else:
        new_d = d + cost
    return new_d def merge(d, cost):
    div_d, mod_d = divmod(d + cost, 10 ** 15)
    if mod_d > l:
        new_d = (div_d + 1) * 10 ** 15 + cost
    else:
        new_d = d + cost
    return new_d merge q = int(input()) int(input()) q def dijkstra(start, matrix):
    # O(V^2)ダイクストラ
    INF = 10 ** 18
    n = len(matrix)
    used = [False] * n
    # 補給回数: 少ないほうがいい
    # 使用燃料: 少ないほうがいい
    # 補給回数が少ないほうがより嬉しい
    # dist[v] = 補給回数 * (10 ** 15) + 使用燃料
    dist = [INF] * n
    dist[start] = 0
    while True:
        v = -1
        for u in range(n):
            if not used[u] and (v == -1 or dist[u] < dist[v]):
                v = u
        if v == -1:
            break
        used[v] = True
        for nxt_v in range(n):
            tmp = merge(dist[v], matrix[v][nxt_v])
            dist[nxt_v] = min(dist[nxt_v], tmp)
    return dist def dijkstra(start, matrix):
    # O(V^2)ダイクストラ
    INF = 10 ** 18
    n = len(matrix)
    used = [False] * n
    # 補給回数: 少ないほうがいい
    # 使用燃料: 少ないほうがいい
    # 補給回数が少ないほうがより嬉しい
    # dist[v] = 補給回数 * (10 ** 15) + 使用燃料
    dist = [INF] * n
    dist[start] = 0
    while True:
        v = -1
        for u in range(n):
            if not used[u] and (v == -1 or dist[u] < dist[v]):
                v = u
        if v == -1:
            break
        used[v] = True
        for nxt_v in range(n):
            tmp = merge(dist[v], matrix[v][nxt_v])
            dist[nxt_v] = min(dist[nxt_v], tmp)
    return dist dijkstra b -= 1 1 b query = [list(map(int, input().split())) for i in range(q)] [list(map(int, input().split())) for i in range(q)] query matrix = [[INF] * n for i in range(n)] [[INF] * n for i in range(n)] matrix
import sys
input = sys.stdin.readline


def dijkstra(start, matrix):
    # O(V^2)ダイクストラ
    INF = 10 ** 18
    n = len(matrix)
    used = [False] * n
    # 補給回数: 少ないほうがいい
    # 使用燃料: 少ないほうがいい
    # 補給回数が少ないほうがより嬉しい
    # dist[v] = 補給回数 * (10 ** 15) + 使用燃料
    dist = [INF] * n
    dist[start] = 0
    while True:
        v = -1
        for u in range(n):
            if not used[u] and (v == -1 or dist[u] < dist[v]):
                v = u
        if v == -1:
            break
        used[v] = True
        for nxt_v in range(n):
            tmp = merge(dist[v], matrix[v][nxt_v])
            dist[nxt_v] = min(dist[nxt_v], tmp)
    return dist

def merge(d, cost):
    div_d, mod_d = divmod(d + cost, 10 ** 15)
    if mod_d > l:
        new_d = (div_d + 1) * 10 ** 15 + cost
    else:
        new_d = d + cost
    return new_d


n, m, l = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]
q = int(input())
query = [list(map(int, input().split())) for i in range(q)]
INF = 10 ** 18

# 隣接行列
matrix = [[INF] * n for i in range(n)]
for i in range(n):
    matrix[i][i] = 0
for a, b, cost in info:
    a -= 1
    b -= 1
    if cost > l:
        continue
    matrix[a][b] = cost
    matrix[b][a] = cost

ans = [[0] * n for i in range(n)] 
for i in range(n):
    tmp = dijkstra(i, matrix)
    for j in range(n):
        ans[i][j] = tmp[j] // (10 ** 15)

for a, b in query:
    a -= 1
    b -= 1
    if ans[a][b] == 1000:
        print(-1)
    else:
        print(ans[a][b])