import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import defaultdict
    n, m, l = map(int, readline().split())
    dist = [[INF] * n for _ in range(n)]

    for _ in range(m):
        a, b, c = map(int, readline().split())
        a, b = a - 1, b - 1
        dist[a][b] = c
        dist[b][a] = c

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

    dist2 = [[INF] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                dist2[i][j] = 1

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

    q = int(readline())

    for _ in range(q):
        s, t = map(int, readline().split())
        s, t = s - 1, t - 1
        if dist2[s][t] == INF:
            print(-1)
        else:
            print(dist2[s][t] - 1)


if __name__ == '__main__':
    main() import sys sys readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 INF = float('INF') INF float('INF') float 'INF' sys.setrecursionlimit(10 ** 5) sys.setrecursionlimit sys setrecursionlimit 10 ** 5 10 5 def main():
    from collections import defaultdict
    n, m, l = map(int, readline().split())
    dist = [[INF] * n for _ in range(n)]

    for _ in range(m):
        a, b, c = map(int, readline().split())
        a, b = a - 1, b - 1
        dist[a][b] = c
        dist[b][a] = c

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

    dist2 = [[INF] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                dist2[i][j] = 1

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

    q = int(readline())

    for _ in range(q):
        s, t = map(int, readline().split())
        s, t = s - 1, t - 1
        if dist2[s][t] == INF:
            print(-1)
        else:
            print(dist2[s][t] - 1) main from collections import defaultdict n, m, l = map(int, readline().split()) n map(int, readline().split()) map int readline().split() ().split () readline split m l [INF] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [INF] * n [INF] INF n dist = [[INF] * n for _ in range(n)] dist [[INF] * n for _ in range(n)] for _ in range(m):
        a, b, c = map(int, readline().split())
        a, b = a - 1, b - 1
        dist[a][b] = c
        dist[b][a] = c

     _ range(m) range m a, b, c = map(int, readline().split()) a map(int, readline().split()) map int readline().split() ().split () readline split b c a, b = a - 1, b - 1 a a - 1 a 1 b b - 1 b 1 dist[a][b] = c dist[a][b] [a] dist a b c dist[b][a] = c dist[b][a] [b] dist b a c for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

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

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

     j range(n) range n dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) dist[i][j] [i] dist i j min(dist[i][j], dist[i][k] + dist[k][j]) min dist[i][j] [i] dist i j dist[i][k] + dist[k][j] dist[i][k] [i] dist i k dist[k][j] [k] dist k j [INF] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [INF] * n [INF] INF n dist2 = [[INF] * n for _ in range(n)] dist2 [[INF] * n for _ in range(n)] 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 for k in range(n):
        for i in range(n):
            for j in range(n):
                dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j])

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

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

     j range(n) range n dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]) dist2[i][j] [i] dist2 i j min(dist2[i][j], dist2[i][k] + dist2[k][j]) min dist2[i][j] [i] dist2 i j dist2[i][k] + dist2[k][j] dist2[i][k] [i] dist2 i k dist2[k][j] [k] dist2 k j q = int(readline()) q int(readline()) int readline() readline for _ in range(q):
        s, t = map(int, readline().split())
        s, t = s - 1, t - 1
        if dist2[s][t] == INF:
            print(-1)
        else:
            print(dist2[s][t] - 1) _ range(q) range q s, t = map(int, readline().split()) s map(int, readline().split()) map int readline().split() ().split () readline split t s, t = s - 1, t - 1 s s - 1 s 1 t t - 1 t 1 if dist2[s][t] == INF:
            print(-1)
        else:
            print(dist2[s][t] - 1) dist2[s][t] == INF dist2[s][t] [s] dist2 s t INF print(-1) print -1 print(dist2[s][t] - 1) print dist2[s][t] - 1 dist2[s][t] [s] dist2 s t 1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD INF = float('INF') float('INF') INF def main():
    from collections import defaultdict
    n, m, l = map(int, readline().split())
    dist = [[INF] * n for _ in range(n)]

    for _ in range(m):
        a, b, c = map(int, readline().split())
        a, b = a - 1, b - 1
        dist[a][b] = c
        dist[b][a] = c

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

    dist2 = [[INF] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                dist2[i][j] = 1

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

    q = int(readline())

    for _ in range(q):
        s, t = map(int, readline().split())
        s, t = s - 1, t - 1
        if dist2[s][t] == INF:
            print(-1)
        else:
            print(dist2[s][t] - 1) def main():
    from collections import defaultdict
    n, m, l = map(int, readline().split())
    dist = [[INF] * n for _ in range(n)]

    for _ in range(m):
        a, b, c = map(int, readline().split())
        a, b = a - 1, b - 1
        dist[a][b] = c
        dist[b][a] = c

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

    dist2 = [[INF] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                dist2[i][j] = 1

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

    q = int(readline())

    for _ in range(q):
        s, t = map(int, readline().split())
        s, t = s - 1, t - 1
        if dist2[s][t] == INF:
            print(-1)
        else:
            print(dist2[s][t] - 1) main readline = sys.stdin.readline sys.stdin.readline readline
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import defaultdict
    n, m, l = map(int, readline().split())
    dist = [[INF] * n for _ in range(n)]

    for _ in range(m):
        a, b, c = map(int, readline().split())
        a, b = a - 1, b - 1
        dist[a][b] = c
        dist[b][a] = c

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

    dist2 = [[INF] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                dist2[i][j] = 1

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

    q = int(readline())

    for _ in range(q):
        s, t = map(int, readline().split())
        s, t = s - 1, t - 1
        if dist2[s][t] == INF:
            print(-1)
        else:
            print(dist2[s][t] - 1)


if __name__ == '__main__':
    main()
