def main():
    from sys import stdin
    input=stdin.readline
    
    import numpy as np
    import scipy.sparse.csgraph as sp

    n, m, l = map(int, input().split())
    abc = [list(map(int, input().split())) for _ in [0]*m]
    q = int(input())
    st = [list(map(int, input().split())) for _ in [0]*q]
    inf = 10**12
    dist = np.full((n, n), inf, dtype=np.int64)
    for i in range(n):
        dist[i][i] = 0
    for a, b, c in abc:
        dist[a-1][b-1] = c
        dist[b-1][a-1] = c
    dist = sp.shortest_path(dist)

    inf = 10**3
    dist2 = np.full((n, n), inf, dtype=np.int16)
    for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                dist2[i][j] = 1
    dist2 = sp.shortest_path(dist2)

    for i in range(n):
        for j in range(n):
            if dist2[i][j] == inf:
                dist2[i][j] = -1
            else:
                dist2[i][j] -= 1
    for s, t in st:
        print(int(dist2[s-1][t-1]))


main() def main():
    from sys import stdin
    input=stdin.readline
    
    import numpy as np
    import scipy.sparse.csgraph as sp

    n, m, l = map(int, input().split())
    abc = [list(map(int, input().split())) for _ in [0]*m]
    q = int(input())
    st = [list(map(int, input().split())) for _ in [0]*q]
    inf = 10**12
    dist = np.full((n, n), inf, dtype=np.int64)
    for i in range(n):
        dist[i][i] = 0
    for a, b, c in abc:
        dist[a-1][b-1] = c
        dist[b-1][a-1] = c
    dist = sp.shortest_path(dist)

    inf = 10**3
    dist2 = np.full((n, n), inf, dtype=np.int16)
    for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                dist2[i][j] = 1
    dist2 = sp.shortest_path(dist2)

    for i in range(n):
        for j in range(n):
            if dist2[i][j] == inf:
                dist2[i][j] = -1
            else:
                dist2[i][j] -= 1
    for s, t in st:
        print(int(dist2[s-1][t-1])) main from sys import stdin input=stdin.readline input stdin.readline stdin readline import numpy as np numpy import scipy.sparse.csgraph as sp scipy.sparse.csgraph 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 [0]*m for _ in [0]*m _ [0]*m [0] 0 m for _ in [0]*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 [0]*m] abc [list(map(int, input().split())) for _ in [0]*m] q = int(input()) q int(input()) int input() input list(map(int, input().split())) for _ in [0]*q for _ in [0]*q _ [0]*q [0] 0 q for _ in [0]*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 [0]*q] st [list(map(int, input().split())) for _ in [0]*q] inf = 10**12 inf 10**12 10 12 dist = np.full((n, n), inf, dtype=np.int64) dist np.full((n, n), inf, dtype=np.int64) np.full np full (n, n) n n inf dtype=np.int64 dtype np.int64 np int64 for i in range(n):
        dist[i][i] = 0
     i range(n) range n dist[i][i] = 0 dist[i][i] [i] dist i i 0 for a, b, c in abc:
        dist[a-1][b-1] = c
        dist[b-1][a-1] = c
     a b c abc dist[a-1][b-1] = c dist[a-1][b-1] [a-1] dist a-1 a 1 b-1 b 1 c dist[b-1][a-1] = c dist[b-1][a-1] [b-1] dist b-1 b 1 a-1 a 1 c dist = sp.shortest_path(dist) dist sp.shortest_path(dist) sp.shortest_path sp shortest_path dist inf = 10**3 inf 10**3 10 3 dist2 = np.full((n, n), inf, dtype=np.int16) dist2 np.full((n, n), inf, dtype=np.int16) np.full np full (n, n) n n inf dtype=np.int16 dtype np.int16 np int16 for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                dist2[i][j] = 1
     i range(n) range n for j in range(n):
            if dist[i][j] <= l:
                dist2[i][j] = 1
     j range(n) range n if dist[i][j] <= l:
                dist2[i][j] = 1
     dist[i][j] <= l dist[i][j] [i] dist i j l dist2[i][j] = 1 dist2[i][j] [i] dist2 i j 1 dist2 = sp.shortest_path(dist2) dist2 sp.shortest_path(dist2) sp.shortest_path sp shortest_path dist2 for i in range(n):
        for j in range(n):
            if dist2[i][j] == inf:
                dist2[i][j] = -1
            else:
                dist2[i][j] -= 1
     i range(n) range n for j in range(n):
            if dist2[i][j] == inf:
                dist2[i][j] = -1
            else:
                dist2[i][j] -= 1
     j range(n) range n if dist2[i][j] == inf:
                dist2[i][j] = -1
            else:
                dist2[i][j] -= 1
     dist2[i][j] == inf dist2[i][j] [i] dist2 i j inf dist2[i][j] = -1 dist2[i][j] [i] dist2 i j -1 dist2[i][j] -= 1 dist2[i][j] [i] dist2 i j 1 for s, t in st:
        print(int(dist2[s-1][t-1])) s t st print(int(dist2[s-1][t-1])) print int(dist2[s-1][t-1]) int dist2[s-1][t-1] [s-1] dist2 s-1 s 1 t-1 t 1 main() main def main():
    from sys import stdin
    input=stdin.readline
    
    import numpy as np
    import scipy.sparse.csgraph as sp

    n, m, l = map(int, input().split())
    abc = [list(map(int, input().split())) for _ in [0]*m]
    q = int(input())
    st = [list(map(int, input().split())) for _ in [0]*q]
    inf = 10**12
    dist = np.full((n, n), inf, dtype=np.int64)
    for i in range(n):
        dist[i][i] = 0
    for a, b, c in abc:
        dist[a-1][b-1] = c
        dist[b-1][a-1] = c
    dist = sp.shortest_path(dist)

    inf = 10**3
    dist2 = np.full((n, n), inf, dtype=np.int16)
    for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                dist2[i][j] = 1
    dist2 = sp.shortest_path(dist2)

    for i in range(n):
        for j in range(n):
            if dist2[i][j] == inf:
                dist2[i][j] = -1
            else:
                dist2[i][j] -= 1
    for s, t in st:
        print(int(dist2[s-1][t-1])) def main():
    from sys import stdin
    input=stdin.readline
    
    import numpy as np
    import scipy.sparse.csgraph as sp

    n, m, l = map(int, input().split())
    abc = [list(map(int, input().split())) for _ in [0]*m]
    q = int(input())
    st = [list(map(int, input().split())) for _ in [0]*q]
    inf = 10**12
    dist = np.full((n, n), inf, dtype=np.int64)
    for i in range(n):
        dist[i][i] = 0
    for a, b, c in abc:
        dist[a-1][b-1] = c
        dist[b-1][a-1] = c
    dist = sp.shortest_path(dist)

    inf = 10**3
    dist2 = np.full((n, n), inf, dtype=np.int16)
    for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                dist2[i][j] = 1
    dist2 = sp.shortest_path(dist2)

    for i in range(n):
        for j in range(n):
            if dist2[i][j] == inf:
                dist2[i][j] = -1
            else:
                dist2[i][j] -= 1
    for s, t in st:
        print(int(dist2[s-1][t-1])) main
def main():
    from sys import stdin
    input=stdin.readline
    
    import numpy as np
    import scipy.sparse.csgraph as sp

    n, m, l = map(int, input().split())
    abc = [list(map(int, input().split())) for _ in [0]*m]
    q = int(input())
    st = [list(map(int, input().split())) for _ in [0]*q]
    inf = 10**12
    dist = np.full((n, n), inf, dtype=np.int64)
    for i in range(n):
        dist[i][i] = 0
    for a, b, c in abc:
        dist[a-1][b-1] = c
        dist[b-1][a-1] = c
    dist = sp.shortest_path(dist)

    inf = 10**3
    dist2 = np.full((n, n), inf, dtype=np.int16)
    for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                dist2[i][j] = 1
    dist2 = sp.shortest_path(dist2)

    for i in range(n):
        for j in range(n):
            if dist2[i][j] == inf:
                dist2[i][j] = -1
            else:
                dist2[i][j] -= 1
    for s, t in st:
        print(int(dist2[s-1][t-1]))


main()
