import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

class WarshallFloyd():
    def __init__(self, N):
        self.N = N
        self.d = [[float("inf") for i in range(N)]
                  for i in range(N)]  # d[u][v] : 辺uvのコスト(存在しないときは'inf')

    def add(self, u, v, c, directed=False):
        """
        0-indexedであることに注意
        u = from, v = to, c = cost
        directed = Trueなら、有向グラフである
        """
        if directed is False:
            self.d[u][v] = c
            self.d[v][u] = c
        else:
            self.d[u][v] = c

    def WarshallFloyd_search(self):
        # これを d[i][j]: iからjへの最短距離 にする
        # 本来無向グラフでのみ全域木を考えるが、二重辺なら有向でも行ける
        for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    self.d[i][j] = min(
                        self.d[i][j], self.d[i][k] + self.d[k][j])
        for i in range(self.N):
            self.d[i][i] = 0
        return self.d

n,m,l = na()
g = WarshallFloyd(n)

for i in range(m):
    a,b,c = na()
    g.add(a-1,b-1,c)

gg = WarshallFloyd(n)
d = g.WarshallFloyd_search()

for i in range(n):
    for j in range(n):
        if d[i][j] <= l:
            gg.add(i,j,1)

q = ni()
dd = gg.WarshallFloyd_search()

for i in range(q):
    s,t = na()
    print(-1 if dd[s-1][t-1] == float('inf') else dd[s-1][t-1]-1) import sys sys stdin = sys.stdin stdin sys.stdin sys stdin ni = lambda: int(ns()) ni lambda: int(ns()) int(ns()) int ns() ns na = lambda: list(map(int, stdin.readline().split())) na lambda: list(map(int, stdin.readline().split())) list(map(int, stdin.readline().split())) list map(int, stdin.readline().split()) map int stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split nn = lambda: list(stdin.readline().split()) nn lambda: list(stdin.readline().split()) list(stdin.readline().split()) list stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split ns = lambda: stdin.readline().rstrip() ns lambda: stdin.readline().rstrip() stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip class WarshallFloyd():
    def __init__(self, N):
        self.N = N
        self.d = [[float("inf") for i in range(N)]
                  for i in range(N)]  # d[u][v] : 辺uvのコスト(存在しないときは'inf')

    def add(self, u, v, c, directed=False):
        """
        0-indexedであることに注意
        u = from, v = to, c = cost
        directed = Trueなら、有向グラフである
        """
        if directed is False:
            self.d[u][v] = c
            self.d[v][u] = c
        else:
            self.d[u][v] = c

    def WarshallFloyd_search(self):
        # これを d[i][j]: iからjへの最短距離 にする
        # 本来無向グラフでのみ全域木を考えるが、二重辺なら有向でも行ける
        for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    self.d[i][j] = min(
                        self.d[i][j], self.d[i][k] + self.d[k][j])
        for i in range(self.N):
            self.d[i][i] = 0
        return self.d WarshallFloyd def __init__(self, N):
        self.N = N
        self.d = [[float("inf") for i in range(N)]
                  for i in range(N)]  # d[u][v] : 辺uvのコスト(存在しないときは'inf')

     __init__ self.N = N self.N self N N [float("inf") for i in range(N)]
                  for i in range(N) for i in range(N) i range(N) range N for i in range(N) [float("inf") for i in range(N)] self.d = [[float("inf") for i in range(N)]
                  for i in range(N)] self.d self d [[float("inf") for i in range(N)]
                  for i in range(N)] self self N N def add(self, u, v, c, directed=False):
        """
        0-indexedであることに注意
        u = from, v = to, c = cost
        directed = Trueなら、有向グラフである
        """
        if directed is False:
            self.d[u][v] = c
            self.d[v][u] = c
        else:
            self.d[u][v] = c

     add """
        0-indexedであることに注意
        u = from, v = to, c = cost
        directed = Trueなら、有向グラフである
        """ if directed is False:
            self.d[u][v] = c
            self.d[v][u] = c
        else:
            self.d[u][v] = c

     directed is False directed False self.d[u][v] = c self.d[u][v] self.d[u] self.d self d u v c self.d[v][u] = c self.d[v][u] self.d[v] self.d self d v u c self.d[u][v] = c self.d[u][v] self.d[u] self.d self d u v c self self u u v v c c directed=False directed False def WarshallFloyd_search(self):
        # これを d[i][j]: iからjへの最短距離 にする
        # 本来無向グラフでのみ全域木を考えるが、二重辺なら有向でも行ける
        for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    self.d[i][j] = min(
                        self.d[i][j], self.d[i][k] + self.d[k][j])
        for i in range(self.N):
            self.d[i][i] = 0
        return self.d WarshallFloyd_search for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    self.d[i][j] = min(
                        self.d[i][j], self.d[i][k] + self.d[k][j])
         k range(self.N) range self.N self N for i in range(self.N):
                for j in range(self.N):
                    self.d[i][j] = min(
                        self.d[i][j], self.d[i][k] + self.d[k][j])
         i range(self.N) range self.N self N for j in range(self.N):
                    self.d[i][j] = min(
                        self.d[i][j], self.d[i][k] + self.d[k][j])
         j range(self.N) range self.N self N self.d[i][j] = min(
                        self.d[i][j], self.d[i][k] + self.d[k][j]) self.d[i][j] self.d[i] self.d self d i j min(
                        self.d[i][j], self.d[i][k] + self.d[k][j]) min self.d[i][j] self.d[i] self.d self d i j self.d[i][k] + self.d[k][j] self.d[i][k] self.d[i] self.d self d i k self.d[k][j] self.d[k] self.d self d k j for i in range(self.N):
            self.d[i][i] = 0
         i range(self.N) range self.N self N self.d[i][i] = 0 self.d[i][i] self.d[i] self.d self d i i 0 return self.d self.d self d self self n,m,l = na() n na() na m l g = WarshallFloyd(n) g WarshallFloyd(n) WarshallFloyd n for i in range(m):
    a,b,c = na()
    g.add(a-1,b-1,c) i range(m) range m a,b,c = na() a na() na b c g.add(a-1,b-1,c) g.add g add a-1 a 1 b-1 b 1 c gg = WarshallFloyd(n) gg WarshallFloyd(n) WarshallFloyd n d = g.WarshallFloyd_search() d g.WarshallFloyd_search() g.WarshallFloyd_search g WarshallFloyd_search for i in range(n):
    for j in range(n):
        if d[i][j] <= l:
            gg.add(i,j,1) i range(n) range n for j in range(n):
        if d[i][j] <= l:
            gg.add(i,j,1) j range(n) range n if d[i][j] <= l:
            gg.add(i,j,1) d[i][j] <= l d[i][j] [i] d i j l gg.add(i,j,1) gg.add gg add i j 1 q = ni() q ni() ni dd = gg.WarshallFloyd_search() dd gg.WarshallFloyd_search() gg.WarshallFloyd_search gg WarshallFloyd_search for i in range(q):
    s,t = na()
    print(-1 if dd[s-1][t-1] == float('inf') else dd[s-1][t-1]-1) i range(q) range q s,t = na() s na() na t print(-1 if dd[s-1][t-1] == float('inf') else dd[s-1][t-1]-1) print -1 if dd[s-1][t-1] == float('inf') else dd[s-1][t-1]-1 dd[s-1][t-1] == float('inf') dd[s-1][t-1] [s-1] dd s-1 s 1 t-1 t 1 float('inf') float 'inf' -1 dd[s-1][t-1]-1 dd[s-1][t-1] [s-1] dd s-1 s 1 t-1 t 1 1 ni = lambda: int(ns()) lambda: int(ns()) ni m,l = na() na() m dd = gg.WarshallFloyd_search() gg.WarshallFloyd_search() dd t = na() na() t stdin = sys.stdin sys.stdin stdin q = ni() ni() q gg = WarshallFloyd(n) WarshallFloyd(n) gg ns = lambda: stdin.readline().rstrip() lambda: stdin.readline().rstrip() ns class WarshallFloyd():
    def __init__(self, N):
        self.N = N
        self.d = [[float("inf") for i in range(N)]
                  for i in range(N)]  # d[u][v] : 辺uvのコスト(存在しないときは'inf')

    def add(self, u, v, c, directed=False):
        """
        0-indexedであることに注意
        u = from, v = to, c = cost
        directed = Trueなら、有向グラフである
        """
        if directed is False:
            self.d[u][v] = c
            self.d[v][u] = c
        else:
            self.d[u][v] = c

    def WarshallFloyd_search(self):
        # これを d[i][j]: iからjへの最短距離 にする
        # 本来無向グラフでのみ全域木を考えるが、二重辺なら有向でも行ける
        for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    self.d[i][j] = min(
                        self.d[i][j], self.d[i][k] + self.d[k][j])
        for i in range(self.N):
            self.d[i][i] = 0
        return self.d class WarshallFloyd():
    def __init__(self, N):
        self.N = N
        self.d = [[float("inf") for i in range(N)]
                  for i in range(N)]  # d[u][v] : 辺uvのコスト(存在しないときは'inf')

    def add(self, u, v, c, directed=False):
        """
        0-indexedであることに注意
        u = from, v = to, c = cost
        directed = Trueなら、有向グラフである
        """
        if directed is False:
            self.d[u][v] = c
            self.d[v][u] = c
        else:
            self.d[u][v] = c

    def WarshallFloyd_search(self):
        # これを d[i][j]: iからjへの最短距離 にする
        # 本来無向グラフでのみ全域木を考えるが、二重辺なら有向でも行ける
        for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    self.d[i][j] = min(
                        self.d[i][j], self.d[i][k] + self.d[k][j])
        for i in range(self.N):
            self.d[i][i] = 0
        return self.d WarshallFloyd nn = lambda: list(stdin.readline().split()) lambda: list(stdin.readline().split()) nn s,t = na() na() s l = na() na() l d = g.WarshallFloyd_search() g.WarshallFloyd_search() d n,m,l = na() na() n b,c = na() na() b a,b,c = na() na() a na = lambda: list(map(int, stdin.readline().split())) lambda: list(map(int, stdin.readline().split())) na c = na() na() c g = WarshallFloyd(n) WarshallFloyd(n) g
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

class WarshallFloyd():
    def __init__(self, N):
        self.N = N
        self.d = [[float("inf") for i in range(N)]
                  for i in range(N)]  # d[u][v] : 辺uvのコスト(存在しないときは'inf')

    def add(self, u, v, c, directed=False):
        """
        0-indexedであることに注意
        u = from, v = to, c = cost
        directed = Trueなら、有向グラフである
        """
        if directed is False:
            self.d[u][v] = c
            self.d[v][u] = c
        else:
            self.d[u][v] = c

    def WarshallFloyd_search(self):
        # これを d[i][j]: iからjへの最短距離 にする
        # 本来無向グラフでのみ全域木を考えるが、二重辺なら有向でも行ける
        for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    self.d[i][j] = min(
                        self.d[i][j], self.d[i][k] + self.d[k][j])
        for i in range(self.N):
            self.d[i][i] = 0
        return self.d

n,m,l = na()
g = WarshallFloyd(n)

for i in range(m):
    a,b,c = na()
    g.add(a-1,b-1,c)

gg = WarshallFloyd(n)
d = g.WarshallFloyd_search()

for i in range(n):
    for j in range(n):
        if d[i][j] <= l:
            gg.add(i,j,1)

q = ni()
dd = gg.WarshallFloyd_search()

for i in range(q):
    s,t = na()
    print(-1 if dd[s-1][t-1] == float('inf') else dd[s-1][t-1]-1)