import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,M,L = MI()


class WarshallFloyd():
    def __init__(self,N):  # Nは頂点の個数
        self.N = N
        self.d = [[float('inf')]*N for i in range(N)]  # d[i][j] = iからjへの最短距離,0-indexed
    def add(self,u,v,c,directed = False):
        if directed is False:  # 無向グラフの場合
            self.d[u][v] = c
            self.d[v][u] = c
        else:  # 有向グラフの場合
            self.d[u][v] = c
    def WarshallFloyd_search(self):
        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])
        return self.d


W = WarshallFloyd(N)
for i in range(M):
    a,b,c = MI()
    W.add(a-1,b-1,c,directed=False)
d = W.WarshallFloyd_search()

d2 = [[float('inf')]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if d[i][j] <= L:
            d2[i][j] = 1

for k in range(N):
    for i in range(N):
        for j in range(N):
            d2[i][j] = min(d2[i][j],d2[i][k]+d2[k][j])

Q = I()
for i in range(Q):
    s,t = MI()
    if d2[s-1][t-1] == float('inf'):
        print(-1)
        continue
    print(d2[s-1][t-1]-1) import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 def I(): return int(sys.stdin.readline().rstrip()) I def MI(): return map(int,sys.stdin.readline().rstrip().split()) MI def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり LI def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし LI2 def S(): return sys.stdin.readline().rstrip() S def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり LS def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし LS2 N,M,L = MI() N MI() MI M L class WarshallFloyd():
    def __init__(self,N):  # Nは頂点の個数
        self.N = N
        self.d = [[float('inf')]*N for i in range(N)]  # d[i][j] = iからjへの最短距離,0-indexed
    def add(self,u,v,c,directed = False):
        if directed is False:  # 無向グラフの場合
            self.d[u][v] = c
            self.d[v][u] = c
        else:  # 有向グラフの場合
            self.d[u][v] = c
    def WarshallFloyd_search(self):
        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])
        return self.d WarshallFloyd def __init__(self,N):  # Nは頂点の個数
        self.N = N
        self.d = [[float('inf')]*N for i in range(N)]  # d[i][j] = iからjへの最短距離,0-indexed
     __init__ self.N = N self.N self N N [float('inf')]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [float('inf')]*N [float('inf')] float('inf') float 'inf' N self.d = [[float('inf')]*N for i in range(N)] self.d self d [[float('inf')]*N for i in range(N)] self self N N def add(self,u,v,c,directed = False):
        if directed is False:  # 無向グラフの場合
            self.d[u][v] = c
            self.d[v][u] = c
        else:  # 有向グラフの場合
            self.d[u][v] = c
     add 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):
        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])
        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 return self.d self.d self d self self W = WarshallFloyd(N) W WarshallFloyd(N) WarshallFloyd N for i in range(M):
    a,b,c = MI()
    W.add(a-1,b-1,c,directed=False) i range(M) range M a,b,c = MI() a MI() MI b c W.add(a-1,b-1,c,directed=False) W.add W add a-1 a 1 b-1 b 1 c directed=False directed False d = W.WarshallFloyd_search() d W.WarshallFloyd_search() W.WarshallFloyd_search W WarshallFloyd_search [float('inf')]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [float('inf')]*N [float('inf')] float('inf') float 'inf' N d2 = [[float('inf')]*N for _ in range(N)] d2 [[float('inf')]*N for _ in range(N)] for i in range(N):
    for j in range(N):
        if d[i][j] <= L:
            d2[i][j] = 1 i range(N) range N for j in range(N):
        if d[i][j] <= L:
            d2[i][j] = 1 j range(N) range N if d[i][j] <= L:
            d2[i][j] = 1 d[i][j] <= L d[i][j] [i] d i j L d2[i][j] = 1 d2[i][j] [i] d2 i j 1 for k in range(N):
    for i in range(N):
        for j in range(N):
            d2[i][j] = min(d2[i][j],d2[i][k]+d2[k][j]) k range(N) range N for i in range(N):
        for j in range(N):
            d2[i][j] = min(d2[i][j],d2[i][k]+d2[k][j]) i range(N) range N for j in range(N):
            d2[i][j] = min(d2[i][j],d2[i][k]+d2[k][j]) j range(N) range N d2[i][j] = min(d2[i][j],d2[i][k]+d2[k][j]) d2[i][j] [i] d2 i j min(d2[i][j],d2[i][k]+d2[k][j]) min d2[i][j] [i] d2 i j d2[i][k]+d2[k][j] d2[i][k] [i] d2 i k d2[k][j] [k] d2 k j Q = I() Q I() I for i in range(Q):
    s,t = MI()
    if d2[s-1][t-1] == float('inf'):
        print(-1)
        continue
    print(d2[s-1][t-1]-1) i range(Q) range Q s,t = MI() s MI() MI t if d2[s-1][t-1] == float('inf'):
        print(-1)
        continue
     d2[s-1][t-1] == float('inf') d2[s-1][t-1] [s-1] d2 s-1 s 1 t-1 t 1 float('inf') float 'inf' print(-1) print -1 continue print(d2[s-1][t-1]-1) print d2[s-1][t-1]-1 d2[s-1][t-1] [s-1] d2 s-1 s 1 t-1 t 1 1 d2 = [[float('inf')]*N for _ in range(N)] [[float('inf')]*N for _ in range(N)] d2 def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし LS2 t = MI() MI() t def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり LI def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし LI2 def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり LS def I(): return int(sys.stdin.readline().rstrip()) def I(): return int(sys.stdin.readline().rstrip()) I N,M,L = MI() MI() N Q = I() I() Q a,b,c = MI() MI() a s,t = MI() MI() s def MI(): return map(int,sys.stdin.readline().rstrip().split()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) MI W = WarshallFloyd(N) WarshallFloyd(N) W M,L = MI() MI() M b,c = MI() MI() b def S(): return sys.stdin.readline().rstrip() def S(): return sys.stdin.readline().rstrip() S d = W.WarshallFloyd_search() W.WarshallFloyd_search() d L = MI() MI() L class WarshallFloyd():
    def __init__(self,N):  # Nは頂点の個数
        self.N = N
        self.d = [[float('inf')]*N for i in range(N)]  # d[i][j] = iからjへの最短距離,0-indexed
    def add(self,u,v,c,directed = False):
        if directed is False:  # 無向グラフの場合
            self.d[u][v] = c
            self.d[v][u] = c
        else:  # 有向グラフの場合
            self.d[u][v] = c
    def WarshallFloyd_search(self):
        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])
        return self.d class WarshallFloyd():
    def __init__(self,N):  # Nは頂点の個数
        self.N = N
        self.d = [[float('inf')]*N for i in range(N)]  # d[i][j] = iからjへの最短距離,0-indexed
    def add(self,u,v,c,directed = False):
        if directed is False:  # 無向グラフの場合
            self.d[u][v] = c
            self.d[v][u] = c
        else:  # 有向グラフの場合
            self.d[u][v] = c
    def WarshallFloyd_search(self):
        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])
        return self.d WarshallFloyd c = MI() MI() c
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,M,L = MI()


class WarshallFloyd():
    def __init__(self,N):  # Nは頂点の個数
        self.N = N
        self.d = [[float('inf')]*N for i in range(N)]  # d[i][j] = iからjへの最短距離,0-indexed
    def add(self,u,v,c,directed = False):
        if directed is False:  # 無向グラフの場合
            self.d[u][v] = c
            self.d[v][u] = c
        else:  # 有向グラフの場合
            self.d[u][v] = c
    def WarshallFloyd_search(self):
        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])
        return self.d


W = WarshallFloyd(N)
for i in range(M):
    a,b,c = MI()
    W.add(a-1,b-1,c,directed=False)
d = W.WarshallFloyd_search()

d2 = [[float('inf')]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if d[i][j] <= L:
            d2[i][j] = 1

for k in range(N):
    for i in range(N):
        for j in range(N):
            d2[i][j] = min(d2[i][j],d2[i][k]+d2[k][j])

Q = I()
for i in range(Q):
    s,t = MI()
    if d2[s-1][t-1] == float('inf'):
        print(-1)
        continue
    print(d2[s-1][t-1]-1)
