import itertools
class WarshallFloyd:
    def __init__(self,n):
        self.v = n
        self.d = [[1e100]*n for _ in range(n)]
        for i in range(n):
            self.d[i][i] = 0

    def path(self,x,y,c):
        if x == y:
            return False
        self.d[x][y] = c
        self.d[y][x] = c
        return True

    def build(self):
        for k in range(self.v):
            for i in range(self.v):
                for j in range(self.v):
                    self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j])
        return self.d

n,m,l = map(int,input().split())
wf = WarshallFloyd(n)
for i in range(m):
    a,b,c = map(int,input().split())
    wf.path(a-1,b-1,c)
d = wf.build()
tank = WarshallFloyd(n)
for i,j in itertools.combinations(range(n),2):
    if d[i][j] <= l:
        tank.path(i,j,1)
d = tank.build()
q = int(input())
ans = [0]*q
for i in range(q):
    s,t = map(int,input().split())
    ans[i] = d[s-1][t-1] - 1 if d[s-1][t-1] != 1e100 else -1
print('\n'.join(str(i) for i in ans)) import itertools itertools class WarshallFloyd:
    def __init__(self,n):
        self.v = n
        self.d = [[1e100]*n for _ in range(n)]
        for i in range(n):
            self.d[i][i] = 0

    def path(self,x,y,c):
        if x == y:
            return False
        self.d[x][y] = c
        self.d[y][x] = c
        return True

    def build(self):
        for k in range(self.v):
            for i in range(self.v):
                for j in range(self.v):
                    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):
        self.v = n
        self.d = [[1e100]*n for _ in range(n)]
        for i in range(n):
            self.d[i][i] = 0

     __init__ self.v = n self.v self v n [1e100]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [1e100]*n [1e100] 1e100 n self.d = [[1e100]*n for _ in range(n)] self.d self d [[1e100]*n for _ in range(n)] for i in range(n):
            self.d[i][i] = 0

     i range(n) range 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 path(self,x,y,c):
        if x == y:
            return False
        self.d[x][y] = c
        self.d[y][x] = c
        return True

     path if x == y:
            return False
         x == y x y return False False self.d[x][y] = c self.d[x][y] self.d[x] self.d self d x y c self.d[y][x] = c self.d[y][x] self.d[y] self.d self d y x c return True True self self x x y y c c def build(self):
        for k in range(self.v):
            for i in range(self.v):
                for j in range(self.v):
                    self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j])
        return self.d build for k in range(self.v):
            for i in range(self.v):
                for j in range(self.v):
                    self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j])
         k range(self.v) range self.v self v for i in range(self.v):
                for j in range(self.v):
                    self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j])
         i range(self.v) range self.v self v for j in range(self.v):
                    self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j])
         j range(self.v) range self.v self v 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 n,m,l = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l wf = WarshallFloyd(n) wf WarshallFloyd(n) WarshallFloyd n for i in range(m):
    a,b,c = map(int,input().split())
    wf.path(a-1,b-1,c) i range(m) range m a,b,c = map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b c wf.path(a-1,b-1,c) wf.path wf path a-1 a 1 b-1 b 1 c d = wf.build() d wf.build() wf.build wf build tank = WarshallFloyd(n) tank WarshallFloyd(n) WarshallFloyd n for i,j in itertools.combinations(range(n),2):
    if d[i][j] <= l:
        tank.path(i,j,1) i j itertools.combinations(range(n),2) itertools.combinations itertools combinations range(n) range n 2 if d[i][j] <= l:
        tank.path(i,j,1) d[i][j] <= l d[i][j] [i] d i j l tank.path(i,j,1) tank.path tank path i j 1 d = tank.build() d tank.build() tank.build tank build q = int(input()) q int(input()) int input() input ans = [0]*q ans [0]*q [0] 0 q for i in range(q):
    s,t = map(int,input().split())
    ans[i] = d[s-1][t-1] - 1 if d[s-1][t-1] != 1e100 else -1 i range(q) range q s,t = map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t ans[i] = d[s-1][t-1] - 1 if d[s-1][t-1] != 1e100 else -1 ans[i] ans i d[s-1][t-1] - 1 if d[s-1][t-1] != 1e100 else -1 d[s-1][t-1] != 1e100 d[s-1][t-1] [s-1] d s-1 s 1 t-1 t 1 1e100 d[s-1][t-1] - 1 d[s-1][t-1] [s-1] d s-1 s 1 t-1 t 1 1 -1 print('\n'.join(str(i) for i in ans)) print '\n'.join(str(i) for i in ans) '\n'.join '\n' join str(i) str i ans = [0]*q [0]*q ans d = tank.build() tank.build() d l = map(int,input().split()) map(int,input().split()) l n,m,l = map(int,input().split()) map(int,input().split()) n b,c = map(int,input().split()) map(int,input().split()) b t = map(int,input().split()) map(int,input().split()) t a,b,c = map(int,input().split()) map(int,input().split()) a q = int(input()) int(input()) q m,l = map(int,input().split()) map(int,input().split()) m wf = WarshallFloyd(n) WarshallFloyd(n) wf s,t = map(int,input().split()) map(int,input().split()) s d = wf.build() wf.build() d tank = WarshallFloyd(n) WarshallFloyd(n) tank class WarshallFloyd:
    def __init__(self,n):
        self.v = n
        self.d = [[1e100]*n for _ in range(n)]
        for i in range(n):
            self.d[i][i] = 0

    def path(self,x,y,c):
        if x == y:
            return False
        self.d[x][y] = c
        self.d[y][x] = c
        return True

    def build(self):
        for k in range(self.v):
            for i in range(self.v):
                for j in range(self.v):
                    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):
        self.v = n
        self.d = [[1e100]*n for _ in range(n)]
        for i in range(n):
            self.d[i][i] = 0

    def path(self,x,y,c):
        if x == y:
            return False
        self.d[x][y] = c
        self.d[y][x] = c
        return True

    def build(self):
        for k in range(self.v):
            for i in range(self.v):
                for j in range(self.v):
                    self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j])
        return self.d WarshallFloyd c = map(int,input().split()) map(int,input().split()) c
import itertools
class WarshallFloyd:
    def __init__(self,n):
        self.v = n
        self.d = [[1e100]*n for _ in range(n)]
        for i in range(n):
            self.d[i][i] = 0

    def path(self,x,y,c):
        if x == y:
            return False
        self.d[x][y] = c
        self.d[y][x] = c
        return True

    def build(self):
        for k in range(self.v):
            for i in range(self.v):
                for j in range(self.v):
                    self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j])
        return self.d

n,m,l = map(int,input().split())
wf = WarshallFloyd(n)
for i in range(m):
    a,b,c = map(int,input().split())
    wf.path(a-1,b-1,c)
d = wf.build()
tank = WarshallFloyd(n)
for i,j in itertools.combinations(range(n),2):
    if d[i][j] <= l:
        tank.path(i,j,1)
d = tank.build()
q = int(input())
ans = [0]*q
for i in range(q):
    s,t = map(int,input().split())
    ans[i] = d[s-1][t-1] - 1 if d[s-1][t-1] != 1e100 else -1
print('\n'.join(str(i) for i in ans))
