import sys

sys.setrecursionlimit(500000)
def input():
    return sys.stdin.readline()[:-1]

def main():
    N,M,L = list(map(int,input().split()))
    e_list = [[] for i in range(N)]
    for i in range(M):
        A,B,C = list(map(int,input().split()))
        A,B = A-1,B-1
        e_list[A].append((B,C))
        e_list[B].append((A,C))

    INF = float('inf')
    D = [[INF]*N for i in range(N)]
    for i in range(N):
        for j,d in e_list[i]:
            D[i][j]=d

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if D[i][j]>D[i][k]+D[k][j]:
                    D[i][j] = D[i][k]+D[k][j]

    E = [[INF]*N for i in range(N)]

    for i in range(N):
        for j in range(N):
            if D[i][j]<=L:
                E[i][j]=1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if E[i][j]>E[i][k]+E[k][j]:
                    E[i][j] = E[i][k]+E[k][j]

    Q = int(input())
    for i in range(Q):
        s,t = list(map(int,input().split()))
        s,t = s-1,t-1
        if E[s][t]>10**28:
            print(-1)
        else:
            print(E[s][t]-1)
            
if __name__ == '__main__':
    main()
 import sys sys sys.setrecursionlimit(500000) sys.setrecursionlimit sys setrecursionlimit 500000 def input():
    return sys.stdin.readline()[:-1] input return sys.stdin.readline()[:-1] sys.stdin.readline()[:-1] sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline :-1 -1 def main():
    N,M,L = list(map(int,input().split()))
    e_list = [[] for i in range(N)]
    for i in range(M):
        A,B,C = list(map(int,input().split()))
        A,B = A-1,B-1
        e_list[A].append((B,C))
        e_list[B].append((A,C))

    INF = float('inf')
    D = [[INF]*N for i in range(N)]
    for i in range(N):
        for j,d in e_list[i]:
            D[i][j]=d

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if D[i][j]>D[i][k]+D[k][j]:
                    D[i][j] = D[i][k]+D[k][j]

    E = [[INF]*N for i in range(N)]

    for i in range(N):
        for j in range(N):
            if D[i][j]<=L:
                E[i][j]=1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if E[i][j]>E[i][k]+E[k][j]:
                    E[i][j] = E[i][k]+E[k][j]

    Q = int(input())
    for i in range(Q):
        s,t = list(map(int,input().split()))
        s,t = s-1,t-1
        if E[s][t]>10**28:
            print(-1)
        else:
            print(E[s][t]-1)
             main N,M,L = list(map(int,input().split())) N list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split M L [] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [] e_list = [[] for i in range(N)] e_list [[] for i in range(N)] for i in range(M):
        A,B,C = list(map(int,input().split()))
        A,B = A-1,B-1
        e_list[A].append((B,C))
        e_list[B].append((A,C))

     i range(M) range M A,B,C = list(map(int,input().split())) A list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split B C A,B = A-1,B-1 A A-1 A 1 B B-1 B 1 e_list[A].append((B,C)) [A].append [A] e_list A append (B,C) B C e_list[B].append((A,C)) [B].append [B] e_list B append (A,C) A C INF = float('inf') INF float('inf') float 'inf' [INF]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [INF]*N [INF] INF N D = [[INF]*N for i in range(N)] D [[INF]*N for i in range(N)] for i in range(N):
        for j,d in e_list[i]:
            D[i][j]=d

     i range(N) range N for j,d in e_list[i]:
            D[i][j]=d

     j d e_list[i] e_list i D[i][j]=d D[i][j] [i] D i j d for k in range(N):
        for i in range(N):
            for j in range(N):
                if D[i][j]>D[i][k]+D[k][j]:
                    D[i][j] = D[i][k]+D[k][j]

     k range(N) range N for i in range(N):
            for j in range(N):
                if D[i][j]>D[i][k]+D[k][j]:
                    D[i][j] = D[i][k]+D[k][j]

     i range(N) range N for j in range(N):
                if D[i][j]>D[i][k]+D[k][j]:
                    D[i][j] = D[i][k]+D[k][j]

     j range(N) range N if D[i][j]>D[i][k]+D[k][j]:
                    D[i][j] = D[i][k]+D[k][j]

     D[i][j]>D[i][k]+D[k][j] 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 D[i][j] = D[i][k]+D[k][j] 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 [INF]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [INF]*N [INF] INF N E = [[INF]*N for i in range(N)] E [[INF]*N for i in range(N)] for i in range(N):
        for j in range(N):
            if D[i][j]<=L:
                E[i][j]=1

     i range(N) range N for j in range(N):
            if D[i][j]<=L:
                E[i][j]=1

     j range(N) range N if D[i][j]<=L:
                E[i][j]=1

     D[i][j]<=L D[i][j] [i] D i j L E[i][j]=1 E[i][j] [i] E i j 1 for k in range(N):
        for i in range(N):
            for j in range(N):
                if E[i][j]>E[i][k]+E[k][j]:
                    E[i][j] = E[i][k]+E[k][j]

     k range(N) range N for i in range(N):
            for j in range(N):
                if E[i][j]>E[i][k]+E[k][j]:
                    E[i][j] = E[i][k]+E[k][j]

     i range(N) range N for j in range(N):
                if E[i][j]>E[i][k]+E[k][j]:
                    E[i][j] = E[i][k]+E[k][j]

     j range(N) range N if E[i][j]>E[i][k]+E[k][j]:
                    E[i][j] = E[i][k]+E[k][j]

     E[i][j]>E[i][k]+E[k][j] E[i][j] [i] E i j E[i][k]+E[k][j] E[i][k] [i] E i k E[k][j] [k] E k j E[i][j] = E[i][k]+E[k][j] E[i][j] [i] E i j E[i][k]+E[k][j] E[i][k] [i] E i k E[k][j] [k] E k j Q = int(input()) Q int(input()) int input() input for i in range(Q):
        s,t = list(map(int,input().split()))
        s,t = s-1,t-1
        if E[s][t]>10**28:
            print(-1)
        else:
            print(E[s][t]-1)
             i range(Q) range Q s,t = list(map(int,input().split())) s list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split t s,t = s-1,t-1 s s-1 s 1 t t-1 t 1 if E[s][t]>10**28:
            print(-1)
        else:
            print(E[s][t]-1)
             E[s][t]>10**28 E[s][t] [s] E s t 10**28 10 28 print(-1) print -1 print(E[s][t]-1) print E[s][t]-1 E[s][t] [s] E s t 1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def input():
    return sys.stdin.readline()[:-1] def input():
    return sys.stdin.readline()[:-1] input def main():
    N,M,L = list(map(int,input().split()))
    e_list = [[] for i in range(N)]
    for i in range(M):
        A,B,C = list(map(int,input().split()))
        A,B = A-1,B-1
        e_list[A].append((B,C))
        e_list[B].append((A,C))

    INF = float('inf')
    D = [[INF]*N for i in range(N)]
    for i in range(N):
        for j,d in e_list[i]:
            D[i][j]=d

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if D[i][j]>D[i][k]+D[k][j]:
                    D[i][j] = D[i][k]+D[k][j]

    E = [[INF]*N for i in range(N)]

    for i in range(N):
        for j in range(N):
            if D[i][j]<=L:
                E[i][j]=1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if E[i][j]>E[i][k]+E[k][j]:
                    E[i][j] = E[i][k]+E[k][j]

    Q = int(input())
    for i in range(Q):
        s,t = list(map(int,input().split()))
        s,t = s-1,t-1
        if E[s][t]>10**28:
            print(-1)
        else:
            print(E[s][t]-1)
             def main():
    N,M,L = list(map(int,input().split()))
    e_list = [[] for i in range(N)]
    for i in range(M):
        A,B,C = list(map(int,input().split()))
        A,B = A-1,B-1
        e_list[A].append((B,C))
        e_list[B].append((A,C))

    INF = float('inf')
    D = [[INF]*N for i in range(N)]
    for i in range(N):
        for j,d in e_list[i]:
            D[i][j]=d

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if D[i][j]>D[i][k]+D[k][j]:
                    D[i][j] = D[i][k]+D[k][j]

    E = [[INF]*N for i in range(N)]

    for i in range(N):
        for j in range(N):
            if D[i][j]<=L:
                E[i][j]=1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if E[i][j]>E[i][k]+E[k][j]:
                    E[i][j] = E[i][k]+E[k][j]

    Q = int(input())
    for i in range(Q):
        s,t = list(map(int,input().split()))
        s,t = s-1,t-1
        if E[s][t]>10**28:
            print(-1)
        else:
            print(E[s][t]-1)
             main
import sys

sys.setrecursionlimit(500000)
def input():
    return sys.stdin.readline()[:-1]

def main():
    N,M,L = list(map(int,input().split()))
    e_list = [[] for i in range(N)]
    for i in range(M):
        A,B,C = list(map(int,input().split()))
        A,B = A-1,B-1
        e_list[A].append((B,C))
        e_list[B].append((A,C))

    INF = float('inf')
    D = [[INF]*N for i in range(N)]
    for i in range(N):
        for j,d in e_list[i]:
            D[i][j]=d

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if D[i][j]>D[i][k]+D[k][j]:
                    D[i][j] = D[i][k]+D[k][j]

    E = [[INF]*N for i in range(N)]

    for i in range(N):
        for j in range(N):
            if D[i][j]<=L:
                E[i][j]=1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if E[i][j]>E[i][k]+E[k][j]:
                    E[i][j] = E[i][k]+E[k][j]

    Q = int(input())
    for i in range(Q):
        s,t = list(map(int,input().split()))
        s,t = s-1,t-1
        if E[s][t]>10**28:
            print(-1)
        else:
            print(E[s][t]-1)
            
if __name__ == '__main__':
    main()

