import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,M,L=map(int,input().split())
    d=[[INF]*N for _ in range(N)]
    for _ in range(M):
        A,B,C=map(lambda x:int(x)-1,input().split())
        d[A][B]=C+1
        d[B][A]=C+1
    Q=int(input())
    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])
    d2=[[INF]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                d2[i][j]=1
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j])
    for _ in range(Q):
        s,t=map(lambda x:int(x)-1,input().split())
        dist=d2[s][t]
        if dist>=INF:
            print(-1)
        else:
            print(dist-1)
            
if __name__ == '__main__':
    main() import sys sys sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 INF=10**18 INF 10**18 10 18 def input():
    return sys.stdin.readline().rstrip() input return sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip def main():
    N,M,L=map(int,input().split())
    d=[[INF]*N for _ in range(N)]
    for _ in range(M):
        A,B,C=map(lambda x:int(x)-1,input().split())
        d[A][B]=C+1
        d[B][A]=C+1
    Q=int(input())
    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])
    d2=[[INF]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                d2[i][j]=1
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j])
    for _ in range(Q):
        s,t=map(lambda x:int(x)-1,input().split())
        dist=d2[s][t]
        if dist>=INF:
            print(-1)
        else:
            print(dist-1)
             main N,M,L=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input 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 d=[[INF]*N for _ in range(N)] d [[INF]*N for _ in range(N)] for _ in range(M):
        A,B,C=map(lambda x:int(x)-1,input().split())
        d[A][B]=C+1
        d[B][A]=C+1
     _ range(M) range M A,B,C=map(lambda x:int(x)-1,input().split()) A map(lambda x:int(x)-1,input().split()) map lambda x:int(x)-1 int(x)-1 int(x) int x 1 x input().split() ().split () input split B C d[A][B]=C+1 d[A][B] [A] d A B C+1 C 1 d[B][A]=C+1 d[B][A] [B] d B A C+1 C 1 Q=int(input()) Q int(input()) int input() input 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 [INF]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF]*N [INF] INF N d2=[[INF]*N for _ in range(N)] d2 [[INF]*N for _ in range(N)] for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                d2[i][j]=1
     i range(N) range N for j in range(N):
            if d[i][j]<=L:
                d2[i][j]=1
     j range(N) range N if d[i][j]<=L:
                d2[i][j]=1
     d[i][j]<=L d[i][j] [i] d i j L d2[i][j]=1 d2[i][j] [i] d2 i j 1 for k in range(N):
        for i in range(N):
            for j in range(N):
                d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j])
     k range(N) range N for i in range(N):
            for j in range(N):
                d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j])
     i range(N) range N for j in range(N):
                d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j])
     j range(N) range N d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j]) d2[i][j] [i] d2 i j min(d2[i][j],d2[i][k]+d2[k][j]) min d2[i][j] [i] d2 i j d2[i][k]+d2[k][j] d2[i][k] [i] d2 i k d2[k][j] [k] d2 k j for _ in range(Q):
        s,t=map(lambda x:int(x)-1,input().split())
        dist=d2[s][t]
        if dist>=INF:
            print(-1)
        else:
            print(dist-1)
             _ range(Q) range Q s,t=map(lambda x:int(x)-1,input().split()) s map(lambda x:int(x)-1,input().split()) map lambda x:int(x)-1 int(x)-1 int(x) int x 1 x input().split() ().split () input split t dist=d2[s][t] dist d2[s][t] [s] d2 s t if dist>=INF:
            print(-1)
        else:
            print(dist-1)
             dist>=INF dist INF print(-1) print -1 print(dist-1) print dist-1 dist 1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main INF=10**18 10**18 INF def input():
    return sys.stdin.readline().rstrip() def input():
    return sys.stdin.readline().rstrip() input def main():
    N,M,L=map(int,input().split())
    d=[[INF]*N for _ in range(N)]
    for _ in range(M):
        A,B,C=map(lambda x:int(x)-1,input().split())
        d[A][B]=C+1
        d[B][A]=C+1
    Q=int(input())
    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])
    d2=[[INF]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                d2[i][j]=1
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j])
    for _ in range(Q):
        s,t=map(lambda x:int(x)-1,input().split())
        dist=d2[s][t]
        if dist>=INF:
            print(-1)
        else:
            print(dist-1)
             def main():
    N,M,L=map(int,input().split())
    d=[[INF]*N for _ in range(N)]
    for _ in range(M):
        A,B,C=map(lambda x:int(x)-1,input().split())
        d[A][B]=C+1
        d[B][A]=C+1
    Q=int(input())
    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])
    d2=[[INF]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                d2[i][j]=1
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j])
    for _ in range(Q):
        s,t=map(lambda x:int(x)-1,input().split())
        dist=d2[s][t]
        if dist>=INF:
            print(-1)
        else:
            print(dist-1)
             main
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,M,L=map(int,input().split())
    d=[[INF]*N for _ in range(N)]
    for _ in range(M):
        A,B,C=map(lambda x:int(x)-1,input().split())
        d[A][B]=C+1
        d[B][A]=C+1
    Q=int(input())
    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])
    d2=[[INF]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                d2[i][j]=1
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j])
    for _ in range(Q):
        s,t=map(lambda x:int(x)-1,input().split())
        dist=d2[s][t]
        if dist>=INF:
            print(-1)
        else:
            print(dist-1)
            
if __name__ == '__main__':
    main()
