import sys
input = sys.stdin.readline

class WarshallFloyd:
    def __init__(self,n):
        self.v = n
        self.d = []
        for i in range(n):
            self.d.append([1e100]*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()

wf = WarshallFloyd(n)
for i in range(1,n):
    for j in range(i):
        if d[i][j] <= l:
            wf.path(i,j,1)

ans = wf.build()

q = int(input())
for i in range(q):
    s,t = map(int,input().split())
    if ans[s-1][t-1] == 1e100:
        print(-1)
    else:
        print(ans[s-1][t-1] - 1) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline class WarshallFloyd:
    def __init__(self,n):
        self.v = n
        self.d = []
        for i in range(n):
            self.d.append([1e100]*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 = []
        for i in range(n):
            self.d.append([1e100]*n)
            self.d[i][i] = 0

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

     i range(n) range n self.d.append([1e100]*n) self.d.append self.d self d append [1e100]*n [1e100] 1e100 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 wf = WarshallFloyd(n) wf WarshallFloyd(n) WarshallFloyd n for i in range(1,n):
    for j in range(i):
        if d[i][j] <= l:
            wf.path(i,j,1) i range(1,n) range 1 n for j in range(i):
        if d[i][j] <= l:
            wf.path(i,j,1) j range(i) range i if d[i][j] <= l:
            wf.path(i,j,1) d[i][j] <= l d[i][j] [i] d i j l wf.path(i,j,1) wf.path wf path i j 1 ans = wf.build() ans wf.build() wf.build wf build q = int(input()) q int(input()) int input() input for i in range(q):
    s,t = map(int,input().split())
    if ans[s-1][t-1] == 1e100:
        print(-1)
    else:
        print(ans[s-1][t-1] - 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 if ans[s-1][t-1] == 1e100:
        print(-1)
    else:
        print(ans[s-1][t-1] - 1) ans[s-1][t-1] == 1e100 ans[s-1][t-1] [s-1] ans s-1 s 1 t-1 t 1 1e100 print(-1) print -1 print(ans[s-1][t-1] - 1) print ans[s-1][t-1] - 1 ans[s-1][t-1] [s-1] ans s-1 s 1 t-1 t 1 1 c = map(int,input().split()) map(int,input().split()) c input = sys.stdin.readline sys.stdin.readline input ans = wf.build() wf.build() ans n,m,l = map(int,input().split()) map(int,input().split()) n d = wf.build() wf.build() d q = int(input()) int(input()) q b,c = map(int,input().split()) map(int,input().split()) b m,l = map(int,input().split()) map(int,input().split()) m class WarshallFloyd:
    def __init__(self,n):
        self.v = n
        self.d = []
        for i in range(n):
            self.d.append([1e100]*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 = []
        for i in range(n):
            self.d.append([1e100]*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 a,b,c = map(int,input().split()) map(int,input().split()) a l = map(int,input().split()) map(int,input().split()) l wf = WarshallFloyd(n) WarshallFloyd(n) wf s,t = map(int,input().split()) map(int,input().split()) s t = map(int,input().split()) map(int,input().split()) t wf = WarshallFloyd(n) WarshallFloyd(n) wf
import sys
input = sys.stdin.readline

class WarshallFloyd:
    def __init__(self,n):
        self.v = n
        self.d = []
        for i in range(n):
            self.d.append([1e100]*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()

wf = WarshallFloyd(n)
for i in range(1,n):
    for j in range(i):
        if d[i][j] <= l:
            wf.path(i,j,1)

ans = wf.build()

q = int(input())
for i in range(q):
    s,t = map(int,input().split())
    if ans[s-1][t-1] == 1e100:
        print(-1)
    else:
        print(ans[s-1][t-1] - 1)
