import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N,M,L = LI()

class WarshallFloyd():
    def __init__(self,N):  # Nは頂点の個数
        self.N = N
        self.d = [[float('inf')]*N for _ 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])
        for i in range(self.N):
            self.d[i][i] = 0
        return self.d

G1 = WarshallFloyd(N)

for i in range(M):
    a,b,c = LI()
    G1.add(a-1,b-1,c,directed=False)

G1.WarshallFloyd_search()

G2 = WarshallFloyd(N)

for i in range(N-1):
    for j in range(i+1,N):
        if G1.d[i][j] <= L:
            G2.add(i,j,1,directed=False)

G2.WarshallFloyd_search()

Q = I()
for i in range(Q):
    s,t = LI()
    if G2.d[s-1][t-1] == float('inf'):
        print(-1)
    else:
        print(G2.d[s-1][t-1]-1)
 import sys sys def I(): return int(sys.stdin.readline().rstrip()) I def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり LI N,M,L = LI() N LI() LI M L class WarshallFloyd():
    def __init__(self,N):  # Nは頂点の個数
        self.N = N
        self.d = [[float('inf')]*N for _ 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])
        for i in range(self.N):
            self.d[i][i] = 0
        return self.d WarshallFloyd def __init__(self,N):  # Nは頂点の個数
        self.N = N
        self.d = [[float('inf')]*N for _ in range(N)]  # d[i][j] = iからjへの最短距離,0-indexed
     __init__ self.N = N self.N self N N [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 self.d = [[float('inf')]*N for _ in range(N)] self.d self d [[float('inf')]*N for _ 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])
        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 G1 = WarshallFloyd(N) G1 WarshallFloyd(N) WarshallFloyd N for i in range(M):
    a,b,c = LI()
    G1.add(a-1,b-1,c,directed=False) i range(M) range M a,b,c = LI() a LI() LI b c G1.add(a-1,b-1,c,directed=False) G1.add G1 add a-1 a 1 b-1 b 1 c directed=False directed False G1.WarshallFloyd_search() G1.WarshallFloyd_search G1 WarshallFloyd_search G2 = WarshallFloyd(N) G2 WarshallFloyd(N) WarshallFloyd N for i in range(N-1):
    for j in range(i+1,N):
        if G1.d[i][j] <= L:
            G2.add(i,j,1,directed=False) i range(N-1) range N-1 N 1 for j in range(i+1,N):
        if G1.d[i][j] <= L:
            G2.add(i,j,1,directed=False) j range(i+1,N) range i+1 i 1 N if G1.d[i][j] <= L:
            G2.add(i,j,1,directed=False) G1.d[i][j] <= L G1.d[i][j] G1.d[i] G1.d G1 d i j L G2.add(i,j,1,directed=False) G2.add G2 add i j 1 directed=False directed False G2.WarshallFloyd_search() G2.WarshallFloyd_search G2 WarshallFloyd_search Q = I() Q I() I for i in range(Q):
    s,t = LI()
    if G2.d[s-1][t-1] == float('inf'):
        print(-1)
    else:
        print(G2.d[s-1][t-1]-1) i range(Q) range Q s,t = LI() s LI() LI t if G2.d[s-1][t-1] == float('inf'):
        print(-1)
    else:
        print(G2.d[s-1][t-1]-1) G2.d[s-1][t-1] == float('inf') G2.d[s-1][t-1] G2.d[s-1] G2.d G2 d s-1 s 1 t-1 t 1 float('inf') float 'inf' print(-1) print -1 print(G2.d[s-1][t-1]-1) print G2.d[s-1][t-1]-1 G2.d[s-1][t-1] G2.d[s-1] G2.d G2 d s-1 s 1 t-1 t 1 1 def I(): return int(sys.stdin.readline().rstrip()) def I(): return int(sys.stdin.readline().rstrip()) I M,L = LI() LI() M b,c = LI() LI() b a,b,c = LI() LI() a N,M,L = LI() LI() N L = LI() LI() L c = LI() LI() c Q = I() I() Q t = LI() LI() t G2 = WarshallFloyd(N) WarshallFloyd(N) G2 s,t = LI() LI() s def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり LI G1 = WarshallFloyd(N) WarshallFloyd(N) G1 class WarshallFloyd():
    def __init__(self,N):  # Nは頂点の個数
        self.N = N
        self.d = [[float('inf')]*N for _ 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])
        for i in range(self.N):
            self.d[i][i] = 0
        return self.d class WarshallFloyd():
    def __init__(self,N):  # Nは頂点の個数
        self.N = N
        self.d = [[float('inf')]*N for _ 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])
        for i in range(self.N):
            self.d[i][i] = 0
        return self.d WarshallFloyd
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N,M,L = LI()

class WarshallFloyd():
    def __init__(self,N):  # Nは頂点の個数
        self.N = N
        self.d = [[float('inf')]*N for _ 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])
        for i in range(self.N):
            self.d[i][i] = 0
        return self.d

G1 = WarshallFloyd(N)

for i in range(M):
    a,b,c = LI()
    G1.add(a-1,b-1,c,directed=False)

G1.WarshallFloyd_search()

G2 = WarshallFloyd(N)

for i in range(N-1):
    for j in range(i+1,N):
        if G1.d[i][j] <= L:
            G2.add(i,j,1,directed=False)

G2.WarshallFloyd_search()

Q = I()
for i in range(Q):
    s,t = LI()
    if G2.d[s-1][t-1] == float('inf'):
        print(-1)
    else:
        print(G2.d[s-1][t-1]-1)

