import sys
input = sys.stdin.readline

def main():
    n, m, l = map(int, input().split())
    dist = [[float('inf')]*n for _ in range(n)]
    for _ in range(m):
        a, b, c = map(int, input().split())
        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 = [[float('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(input())
    for _ in range(q):
        s, t = map(int, input().split())
        s -= 1
        t -= 1
        if dist2[s][t] == float('inf'):
            print(-1)
            continue
        ans = dist2[s][t]
        print(ans-1)

if __name__ == "__main__":
    main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def main():
    n, m, l = map(int, input().split())
    dist = [[float('inf')]*n for _ in range(n)]
    for _ in range(m):
        a, b, c = map(int, input().split())
        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 = [[float('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(input())
    for _ in range(q):
        s, t = map(int, input().split())
        s -= 1
        t -= 1
        if dist2[s][t] == float('inf'):
            print(-1)
            continue
        ans = dist2[s][t]
        print(ans-1) main n, m, l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l [float('inf')]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [float('inf')]*n [float('inf')] float('inf') float 'inf' n dist = [[float('inf')]*n for _ in range(n)] dist [[float('inf')]*n for _ in range(n)] for _ in range(m):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        dist[a][b] = c
        dist[b][a] = c

     _ 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 a -= 1 a 1 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 [float('inf')]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [float('inf')]*n [float('inf')] float('inf') float 'inf' n dist2 = [[float('inf')]*n for _ in range(n)] dist2 [[float('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(input()) q int(input()) int input() input for _ in range(q):
        s, t = map(int, input().split())
        s -= 1
        t -= 1
        if dist2[s][t] == float('inf'):
            print(-1)
            continue
        ans = dist2[s][t]
        print(ans-1) _ range(q) range q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t s -= 1 s 1 t -= 1 t 1 if dist2[s][t] == float('inf'):
            print(-1)
            continue
         dist2[s][t] == float('inf') dist2[s][t] [s] dist2 s t float('inf') float 'inf' print(-1) print -1 continue ans = dist2[s][t] ans dist2[s][t] [s] dist2 s t print(ans-1) print ans-1 ans 1 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    n, m, l = map(int, input().split())
    dist = [[float('inf')]*n for _ in range(n)]
    for _ in range(m):
        a, b, c = map(int, input().split())
        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 = [[float('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(input())
    for _ in range(q):
        s, t = map(int, input().split())
        s -= 1
        t -= 1
        if dist2[s][t] == float('inf'):
            print(-1)
            continue
        ans = dist2[s][t]
        print(ans-1) def main():
    n, m, l = map(int, input().split())
    dist = [[float('inf')]*n for _ in range(n)]
    for _ in range(m):
        a, b, c = map(int, input().split())
        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 = [[float('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(input())
    for _ in range(q):
        s, t = map(int, input().split())
        s -= 1
        t -= 1
        if dist2[s][t] == float('inf'):
            print(-1)
            continue
        ans = dist2[s][t]
        print(ans-1) main input = sys.stdin.readline sys.stdin.readline input
import sys
input = sys.stdin.readline

def main():
    n, m, l = map(int, input().split())
    dist = [[float('inf')]*n for _ in range(n)]
    for _ in range(m):
        a, b, c = map(int, input().split())
        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 = [[float('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(input())
    for _ in range(q):
        s, t = map(int, input().split())
        s -= 1
        t -= 1
        if dist2[s][t] == float('inf'):
            print(-1)
            continue
        ans = dist2[s][t]
        print(ans-1)

if __name__ == "__main__":
    main()