import sys
input = sys.stdin.readline

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])

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)
wf.build()
d = [[1e100]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if i == j:
            d[i][j] = 0
        elif wf.d[i][j] <= l:
            d[i][j] = 1

for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

q = int(input())
for i in range(q):
    s,t = map(int,input().split())
    ans = d[s-1][t-1]
    if ans == 1e100:
        print(-1)
    else:
        print(ans - 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 = [[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]) 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]) 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 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 wf.build() wf.build wf build [1e100]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [1e100]*n [1e100] 1e100 n d = [[1e100]*n for _ in range(n)] d [[1e100]*n for _ in range(n)] for i in range(n):
    for j in range(n):
        if i == j:
            d[i][j] = 0
        elif wf.d[i][j] <= l:
            d[i][j] = 1 i range(n) range n for j in range(n):
        if i == j:
            d[i][j] = 0
        elif wf.d[i][j] <= l:
            d[i][j] = 1 j range(n) range n if i == j:
            d[i][j] = 0
        elif wf.d[i][j] <= l:
            d[i][j] = 1 i == j i j d[i][j] = 0 d[i][j] [i] d i j 0 elif wf.d[i][j] <= l:
            d[i][j] = 1 wf.d[i][j] <= l wf.d[i][j] wf.d[i] wf.d wf d i j l d[i][j] = 1 d[i][j] [i] d i j 1 for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]) k range(n) range n for i in range(n):
        for j in range(n):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]) i range(n) range n for j in range(n):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]) j range(n) range n d[i][j] = min(d[i][j], d[i][k] + d[k][j]) d[i][j] [i] d i j min(d[i][j], d[i][k] + d[k][j]) min d[i][j] [i] d i j d[i][k] + d[k][j] d[i][k] [i] d i k d[k][j] [k] d k j q = int(input()) q int(input()) int input() input for i in range(q):
    s,t = map(int,input().split())
    ans = d[s-1][t-1]
    if ans == 1e100:
        print(-1)
    else:
        print(ans - 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 = d[s-1][t-1] ans d[s-1][t-1] [s-1] d s-1 s 1 t-1 t 1 if ans == 1e100:
        print(-1)
    else:
        print(ans - 1) ans == 1e100 ans 1e100 print(-1) print -1 print(ans - 1) print ans - 1 ans 1 q = int(input()) int(input()) q wf = WarshallFloyd(n) WarshallFloyd(n) wf n,m,l = map(int,input().split()) map(int,input().split()) n ans = d[s-1][t-1] d[s-1][t-1] ans s,t = map(int,input().split()) map(int,input().split()) s a,b,c = map(int,input().split()) map(int,input().split()) a 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]) 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]) WarshallFloyd t = map(int,input().split()) map(int,input().split()) t input = sys.stdin.readline sys.stdin.readline input m,l = map(int,input().split()) map(int,input().split()) m l = map(int,input().split()) map(int,input().split()) l b,c = map(int,input().split()) map(int,input().split()) b c = map(int,input().split()) map(int,input().split()) c d = [[1e100]*n for _ in range(n)] [[1e100]*n for _ in range(n)] d
import sys
input = sys.stdin.readline

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])

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)
wf.build()
d = [[1e100]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if i == j:
            d[i][j] = 0
        elif wf.d[i][j] <= l:
            d[i][j] = 1

for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

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