import sys
input = sys.stdin.readline

class Graph():  #non-directed
    def __init__(self, n, edge):
        self.n = n
        self.graph = [[] for _ in range(n)]
        for e in edge:
            self.graph[e[0] - 1].append((e[1] - 1, e[2]))
            self.graph[e[1] - 1].append((e[0] - 1, e[2]))

    def warshall_floyd(self, INF=10**18):
        dist = [[INF for j in range(self.n)] for i in range(self.n)]
        for i in range(self.n):
            dist[i][i] = 0
        for i in range(self.n):
            for j, cost in self.graph[i]:
                dist[i][j] = cost
        for k in range(self.n):
            for i in range(self.n):
                for j in range(self.n):
                    if dist[i][k] != INF and dist[k][j] != INF:
                        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
        return dist

INF = 10**18

N, M, L = map(int, input().split())
E = [tuple(map(int, input().split())) for _ in range(M)]

G = Graph(N, E)
D = G.warshall_floyd()

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if D[i][j] > L:
            D[i][j] = INF
        else:
            D[i][j] = 1

for k in range(N):
    for i in range(N):
        for j in range(N):
            if D[i][k] != INF and D[k][j] != INF:
                D[i][j] = min(D[i][j], D[i][k] + D[k][j])

Q = int(input())

for _ in range(Q):
    s, t = map(int, input().split())
    if D[s - 1][t - 1] != INF:
        print(D[s - 1][t - 1] - 1)
    else:
        print(-1) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline class Graph():  #non-directed
    def __init__(self, n, edge):
        self.n = n
        self.graph = [[] for _ in range(n)]
        for e in edge:
            self.graph[e[0] - 1].append((e[1] - 1, e[2]))
            self.graph[e[1] - 1].append((e[0] - 1, e[2]))

    def warshall_floyd(self, INF=10**18):
        dist = [[INF for j in range(self.n)] for i in range(self.n)]
        for i in range(self.n):
            dist[i][i] = 0
        for i in range(self.n):
            for j, cost in self.graph[i]:
                dist[i][j] = cost
        for k in range(self.n):
            for i in range(self.n):
                for j in range(self.n):
                    if dist[i][k] != INF and dist[k][j] != INF:
                        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
        return dist Graph def __init__(self, n, edge):
        self.n = n
        self.graph = [[] for _ in range(n)]
        for e in edge:
            self.graph[e[0] - 1].append((e[1] - 1, e[2]))
            self.graph[e[1] - 1].append((e[0] - 1, e[2]))

     __init__ self.n = n self.n self n n [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] self.graph = [[] for _ in range(n)] self.graph self graph [[] for _ in range(n)] for e in edge:
            self.graph[e[0] - 1].append((e[1] - 1, e[2]))
            self.graph[e[1] - 1].append((e[0] - 1, e[2]))

     e edge self.graph[e[0] - 1].append((e[1] - 1, e[2])) self.graph[e[0] - 1].append self.graph[e[0] - 1] self.graph self graph e[0] - 1 e[0] e 0 1 append (e[1] - 1, e[2]) e[1] - 1 e[1] e 1 1 e[2] e 2 self.graph[e[1] - 1].append((e[0] - 1, e[2])) self.graph[e[1] - 1].append self.graph[e[1] - 1] self.graph self graph e[1] - 1 e[1] e 1 1 append (e[0] - 1, e[2]) e[0] - 1 e[0] e 0 1 e[2] e 2 self self n n edge edge def warshall_floyd(self, INF=10**18):
        dist = [[INF for j in range(self.n)] for i in range(self.n)]
        for i in range(self.n):
            dist[i][i] = 0
        for i in range(self.n):
            for j, cost in self.graph[i]:
                dist[i][j] = cost
        for k in range(self.n):
            for i in range(self.n):
                for j in range(self.n):
                    if dist[i][k] != INF and dist[k][j] != INF:
                        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
        return dist warshall_floyd [INF for j in range(self.n)] for i in range(self.n) for i in range(self.n) i range(self.n) range self.n self n for i in range(self.n) [INF for j in range(self.n)] dist = [[INF for j in range(self.n)] for i in range(self.n)] dist [[INF for j in range(self.n)] for i in range(self.n)] for i in range(self.n):
            dist[i][i] = 0
         i range(self.n) range self.n self n dist[i][i] = 0 dist[i][i] [i] dist i i 0 for i in range(self.n):
            for j, cost in self.graph[i]:
                dist[i][j] = cost
         i range(self.n) range self.n self n for j, cost in self.graph[i]:
                dist[i][j] = cost
         j cost self.graph[i] self.graph self graph i dist[i][j] = cost dist[i][j] [i] dist i j cost for k in range(self.n):
            for i in range(self.n):
                for j in range(self.n):
                    if dist[i][k] != INF and dist[k][j] != INF:
                        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
         k range(self.n) range self.n self n for i in range(self.n):
                for j in range(self.n):
                    if dist[i][k] != INF and dist[k][j] != INF:
                        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
         i range(self.n) range self.n self n for j in range(self.n):
                    if dist[i][k] != INF and dist[k][j] != INF:
                        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
         j range(self.n) range self.n self n if dist[i][k] != INF and dist[k][j] != INF:
                        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
         dist[i][k] != INF and dist[k][j] != INF dist[i][k] != INF dist[i][k] [i] dist i k INF dist[k][j] != INF dist[k][j] [k] dist k j INF dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) dist[i][j] [i] dist i j min(dist[i][j], dist[i][k] + dist[k][j]) min dist[i][j] [i] dist i j dist[i][k] + dist[k][j] dist[i][k] [i] dist i k dist[k][j] [k] dist k j return dist dist self self INF=10**18 INF 10**18 10 18 INF = 10**18 INF 10**18 10 18 N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L tuple(map(int, input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) tuple(map(int, input().split())) tuple map(int, input().split()) map int input().split() ().split () input split E = [tuple(map(int, input().split())) for _ in range(M)] E [tuple(map(int, input().split())) for _ in range(M)] G = Graph(N, E) G Graph(N, E) Graph N E D = G.warshall_floyd() D G.warshall_floyd() G.warshall_floyd G warshall_floyd for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if D[i][j] > L:
            D[i][j] = INF
        else:
            D[i][j] = 1 i range(N) range N for j in range(N):
        if i == j:
            continue
        if D[i][j] > L:
            D[i][j] = INF
        else:
            D[i][j] = 1 j range(N) range N if i == j:
            continue
         i == j i j continue if D[i][j] > L:
            D[i][j] = INF
        else:
            D[i][j] = 1 D[i][j] > L D[i][j] [i] D i j L D[i][j] = INF D[i][j] [i] D i j INF D[i][j] = 1 D[i][j] [i] D i j 1 for k in range(N):
    for i in range(N):
        for j in range(N):
            if D[i][k] != INF and D[k][j] != INF:
                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):
            if D[i][k] != INF and D[k][j] != INF:
                D[i][j] = min(D[i][j], D[i][k] + D[k][j]) i range(N) range N for j in range(N):
            if D[i][k] != INF and D[k][j] != INF:
                D[i][j] = min(D[i][j], D[i][k] + D[k][j]) j range(N) range N if D[i][k] != INF and D[k][j] != INF:
                D[i][j] = min(D[i][j], D[i][k] + D[k][j]) D[i][k] != INF and D[k][j] != INF D[i][k] != INF D[i][k] [i] D i k INF D[k][j] != INF D[k][j] [k] D k j INF 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 Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s, t = map(int, input().split())
    if D[s - 1][t - 1] != INF:
        print(D[s - 1][t - 1] - 1)
    else:
        print(-1) _ range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t if D[s - 1][t - 1] != INF:
        print(D[s - 1][t - 1] - 1)
    else:
        print(-1) D[s - 1][t - 1] != INF D[s - 1][t - 1] [s - 1] D s - 1 s 1 t - 1 t 1 INF print(D[s - 1][t - 1] - 1) print D[s - 1][t - 1] - 1 D[s - 1][t - 1] [s - 1] D s - 1 s 1 t - 1 t 1 1 print(-1) print -1 M, L = map(int, input().split()) map(int, input().split()) M input = sys.stdin.readline sys.stdin.readline input D = G.warshall_floyd() G.warshall_floyd() D L = map(int, input().split()) map(int, input().split()) L G = Graph(N, E) Graph(N, E) G s, t = map(int, input().split()) map(int, input().split()) s N, M, L = map(int, input().split()) map(int, input().split()) N Q = int(input()) int(input()) Q INF = 10**18 10**18 INF E = [tuple(map(int, input().split())) for _ in range(M)] [tuple(map(int, input().split())) for _ in range(M)] E t = map(int, input().split()) map(int, input().split()) t class Graph():  #non-directed
    def __init__(self, n, edge):
        self.n = n
        self.graph = [[] for _ in range(n)]
        for e in edge:
            self.graph[e[0] - 1].append((e[1] - 1, e[2]))
            self.graph[e[1] - 1].append((e[0] - 1, e[2]))

    def warshall_floyd(self, INF=10**18):
        dist = [[INF for j in range(self.n)] for i in range(self.n)]
        for i in range(self.n):
            dist[i][i] = 0
        for i in range(self.n):
            for j, cost in self.graph[i]:
                dist[i][j] = cost
        for k in range(self.n):
            for i in range(self.n):
                for j in range(self.n):
                    if dist[i][k] != INF and dist[k][j] != INF:
                        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
        return dist class Graph():  #non-directed
    def __init__(self, n, edge):
        self.n = n
        self.graph = [[] for _ in range(n)]
        for e in edge:
            self.graph[e[0] - 1].append((e[1] - 1, e[2]))
            self.graph[e[1] - 1].append((e[0] - 1, e[2]))

    def warshall_floyd(self, INF=10**18):
        dist = [[INF for j in range(self.n)] for i in range(self.n)]
        for i in range(self.n):
            dist[i][i] = 0
        for i in range(self.n):
            for j, cost in self.graph[i]:
                dist[i][j] = cost
        for k in range(self.n):
            for i in range(self.n):
                for j in range(self.n):
                    if dist[i][k] != INF and dist[k][j] != INF:
                        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
        return dist Graph
import sys
input = sys.stdin.readline

class Graph():  #non-directed
    def __init__(self, n, edge):
        self.n = n
        self.graph = [[] for _ in range(n)]
        for e in edge:
            self.graph[e[0] - 1].append((e[1] - 1, e[2]))
            self.graph[e[1] - 1].append((e[0] - 1, e[2]))

    def warshall_floyd(self, INF=10**18):
        dist = [[INF for j in range(self.n)] for i in range(self.n)]
        for i in range(self.n):
            dist[i][i] = 0
        for i in range(self.n):
            for j, cost in self.graph[i]:
                dist[i][j] = cost
        for k in range(self.n):
            for i in range(self.n):
                for j in range(self.n):
                    if dist[i][k] != INF and dist[k][j] != INF:
                        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
        return dist

INF = 10**18

N, M, L = map(int, input().split())
E = [tuple(map(int, input().split())) for _ in range(M)]

G = Graph(N, E)
D = G.warshall_floyd()

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if D[i][j] > L:
            D[i][j] = INF
        else:
            D[i][j] = 1

for k in range(N):
    for i in range(N):
        for j in range(N):
            if D[i][k] != INF and D[k][j] != INF:
                D[i][j] = min(D[i][j], D[i][k] + D[k][j])

Q = int(input())

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