N,M,L = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in range(M)]
Q = int(input())

class WarshallFloyd:
    def __init__(self,n):
        self.n = n
        self.inf = 100000000000000
        self.d = [[self.inf for _ in range(n)] for _ in range(n)]
        for i in range(self.n):
            self.d[i][i] = 0
    def register(self,v1,v2,l,multiple=True):
        self.d[v1][v2] = l
        if multiple:
            self.d[v2][v1] = l
    
    def solve(self):
        for i in range(self.n):
            for j in range(self.n):
                for k in range(self.n):
                    self.d[j][k] = min(self.d[j][k],self.d[j][i]+self.d[i][k])
        return self.d

W = WarshallFloyd(N)
for a,b,c in ABC:
    W.register(a-1,b-1,c)
D = W.solve()

WL = WarshallFloyd(N)
for i in range(N):
    for j in range(N):
        if D[i][j] <= L and i != j:
            WL.register(i,j,1)
DL = WL.solve()
ST = [list(map(int,input().split())) for _ in range(Q)]
for i in range(Q):
    s,t = ST[i]
    transition = DL[s-1][t-1]
    if transition == 100000000000000:
        print(-1)
    else:
        print(transition-1) 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 _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split ABC = [list(map(int,input().split())) for _ in range(M)] ABC [list(map(int,input().split())) for _ in range(M)] Q = int(input()) Q int(input()) int input() input class WarshallFloyd:
    def __init__(self,n):
        self.n = n
        self.inf = 100000000000000
        self.d = [[self.inf for _ in range(n)] for _ in range(n)]
        for i in range(self.n):
            self.d[i][i] = 0
    def register(self,v1,v2,l,multiple=True):
        self.d[v1][v2] = l
        if multiple:
            self.d[v2][v1] = l
    
    def solve(self):
        for i in range(self.n):
            for j in range(self.n):
                for k in range(self.n):
                    self.d[j][k] = min(self.d[j][k],self.d[j][i]+self.d[i][k])
        return self.d WarshallFloyd def __init__(self,n):
        self.n = n
        self.inf = 100000000000000
        self.d = [[self.inf for _ in range(n)] for _ in range(n)]
        for i in range(self.n):
            self.d[i][i] = 0
     __init__ self.n = n self.n self n n self.inf = 100000000000000 self.inf self inf 100000000000000 [self.inf for _ in range(n)] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [self.inf for _ in range(n)] self.d = [[self.inf for _ in range(n)] for _ in range(n)] self.d self d [[self.inf for _ in range(n)] for _ in range(n)] 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 self self n n def register(self,v1,v2,l,multiple=True):
        self.d[v1][v2] = l
        if multiple:
            self.d[v2][v1] = l
    
     register self.d[v1][v2] = l self.d[v1][v2] self.d[v1] self.d self d v1 v2 l if multiple:
            self.d[v2][v1] = l
    
     multiple self.d[v2][v1] = l self.d[v2][v1] self.d[v2] self.d self d v2 v1 l self self v1 v1 v2 v2 l l multiple=True multiple True def solve(self):
        for i in range(self.n):
            for j in range(self.n):
                for k in range(self.n):
                    self.d[j][k] = min(self.d[j][k],self.d[j][i]+self.d[i][k])
        return self.d solve for i in range(self.n):
            for j in range(self.n):
                for k in range(self.n):
                    self.d[j][k] = min(self.d[j][k],self.d[j][i]+self.d[i][k])
         i range(self.n) range self.n self n for j in range(self.n):
                for k in range(self.n):
                    self.d[j][k] = min(self.d[j][k],self.d[j][i]+self.d[i][k])
         j range(self.n) range self.n self n for k in range(self.n):
                    self.d[j][k] = min(self.d[j][k],self.d[j][i]+self.d[i][k])
         k range(self.n) range self.n self n self.d[j][k] = min(self.d[j][k],self.d[j][i]+self.d[i][k]) self.d[j][k] self.d[j] self.d self d j k min(self.d[j][k],self.d[j][i]+self.d[i][k]) min self.d[j][k] self.d[j] self.d self d j k self.d[j][i]+self.d[i][k] self.d[j][i] self.d[j] self.d self d j i self.d[i][k] self.d[i] self.d self d i k return self.d self.d self d self self W = WarshallFloyd(N) W WarshallFloyd(N) WarshallFloyd N for a,b,c in ABC:
    W.register(a-1,b-1,c) a b c ABC W.register(a-1,b-1,c) W.register W register a-1 a 1 b-1 b 1 c D = W.solve() D W.solve() W.solve W solve WL = WarshallFloyd(N) WL WarshallFloyd(N) WarshallFloyd N for i in range(N):
    for j in range(N):
        if D[i][j] <= L and i != j:
            WL.register(i,j,1) i range(N) range N for j in range(N):
        if D[i][j] <= L and i != j:
            WL.register(i,j,1) j range(N) range N if D[i][j] <= L and i != j:
            WL.register(i,j,1) D[i][j] <= L and i != j D[i][j] <= L D[i][j] [i] D i j L i != j i j WL.register(i,j,1) WL.register WL register i j 1 DL = WL.solve() DL WL.solve() WL.solve WL solve list(map(int,input().split())) for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split ST = [list(map(int,input().split())) for _ in range(Q)] ST [list(map(int,input().split())) for _ in range(Q)] for i in range(Q):
    s,t = ST[i]
    transition = DL[s-1][t-1]
    if transition == 100000000000000:
        print(-1)
    else:
        print(transition-1) i range(Q) range Q s,t = ST[i] s ST[i] ST i t transition = DL[s-1][t-1] transition DL[s-1][t-1] [s-1] DL s-1 s 1 t-1 t 1 if transition == 100000000000000:
        print(-1)
    else:
        print(transition-1) transition == 100000000000000 transition 100000000000000 print(-1) print -1 print(transition-1) print transition-1 transition 1 L = map(int,input().split()) map(int,input().split()) L ST = [list(map(int,input().split())) for _ in range(Q)] [list(map(int,input().split())) for _ in range(Q)] ST D = W.solve() W.solve() D W = WarshallFloyd(N) WarshallFloyd(N) W transition = DL[s-1][t-1] DL[s-1][t-1] transition ABC = [list(map(int,input().split())) for _ in range(M)] [list(map(int,input().split())) for _ in range(M)] ABC WL = WarshallFloyd(N) WarshallFloyd(N) WL t = ST[i] ST[i] t DL = WL.solve() WL.solve() DL Q = int(input()) int(input()) Q N,M,L = map(int,input().split()) map(int,input().split()) N class WarshallFloyd:
    def __init__(self,n):
        self.n = n
        self.inf = 100000000000000
        self.d = [[self.inf for _ in range(n)] for _ in range(n)]
        for i in range(self.n):
            self.d[i][i] = 0
    def register(self,v1,v2,l,multiple=True):
        self.d[v1][v2] = l
        if multiple:
            self.d[v2][v1] = l
    
    def solve(self):
        for i in range(self.n):
            for j in range(self.n):
                for k in range(self.n):
                    self.d[j][k] = min(self.d[j][k],self.d[j][i]+self.d[i][k])
        return self.d class WarshallFloyd:
    def __init__(self,n):
        self.n = n
        self.inf = 100000000000000
        self.d = [[self.inf for _ in range(n)] for _ in range(n)]
        for i in range(self.n):
            self.d[i][i] = 0
    def register(self,v1,v2,l,multiple=True):
        self.d[v1][v2] = l
        if multiple:
            self.d[v2][v1] = l
    
    def solve(self):
        for i in range(self.n):
            for j in range(self.n):
                for k in range(self.n):
                    self.d[j][k] = min(self.d[j][k],self.d[j][i]+self.d[i][k])
        return self.d WarshallFloyd s,t = ST[i] ST[i] s M,L = map(int,input().split()) map(int,input().split()) M
N,M,L = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in range(M)]
Q = int(input())

class WarshallFloyd:
    def __init__(self,n):
        self.n = n
        self.inf = 100000000000000
        self.d = [[self.inf for _ in range(n)] for _ in range(n)]
        for i in range(self.n):
            self.d[i][i] = 0
    def register(self,v1,v2,l,multiple=True):
        self.d[v1][v2] = l
        if multiple:
            self.d[v2][v1] = l
    
    def solve(self):
        for i in range(self.n):
            for j in range(self.n):
                for k in range(self.n):
                    self.d[j][k] = min(self.d[j][k],self.d[j][i]+self.d[i][k])
        return self.d

W = WarshallFloyd(N)
for a,b,c in ABC:
    W.register(a-1,b-1,c)
D = W.solve()

WL = WarshallFloyd(N)
for i in range(N):
    for j in range(N):
        if D[i][j] <= L and i != j:
            WL.register(i,j,1)
DL = WL.solve()
ST = [list(map(int,input().split())) for _ in range(Q)]
for i in range(Q):
    s,t = ST[i]
    transition = DL[s-1][t-1]
    if transition == 100000000000000:
        print(-1)
    else:
        print(transition-1)