def main():
    import sys
    input = sys.stdin.readline
    n,m,l = map(int,input().split())
    E = [[float("INF")]*n for i in range(n)]
    for i in range(m):
        a,b,c = map(int,input().split())
        E[a-1][b-1] = c
        E[b-1][a-1] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                E[i][j] = min(E[i][j],E[i][k]+E[k][j])
    wa = [[float("INF")]*n for i in range(n)]
    for i in range(n):
        for j in range(n):
            if E[i][j] <= l:
                wa[i][j] = 1
    for k in range(n):
        for i in range(n):
            for j in range(n):
                wa[i][j] = min(wa[i][j],wa[i][k]+wa[k][j])
    
    x = int(input())
    for i in range(x):
        s,g = map(int,input().split())
        if wa[s-1][g-1] == float("INF"):
            print(-1)
        else:
            print(wa[s-1][g-1]-1)

    
if __name__ == "__main__":
    main() def main():
    import sys
    input = sys.stdin.readline
    n,m,l = map(int,input().split())
    E = [[float("INF")]*n for i in range(n)]
    for i in range(m):
        a,b,c = map(int,input().split())
        E[a-1][b-1] = c
        E[b-1][a-1] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                E[i][j] = min(E[i][j],E[i][k]+E[k][j])
    wa = [[float("INF")]*n for i in range(n)]
    for i in range(n):
        for j in range(n):
            if E[i][j] <= l:
                wa[i][j] = 1
    for k in range(n):
        for i in range(n):
            for j in range(n):
                wa[i][j] = min(wa[i][j],wa[i][k]+wa[k][j])
    
    x = int(input())
    for i in range(x):
        s,g = map(int,input().split())
        if wa[s-1][g-1] == float("INF"):
            print(-1)
        else:
            print(wa[s-1][g-1]-1)

     main import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline 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 i in range(n) for i in range(n) i range(n) range n for i in range(n) [float("INF")]*n [float("INF")] float("INF") float "INF" n E = [[float("INF")]*n for i in range(n)] E [[float("INF")]*n for i in range(n)] for i in range(m):
        a,b,c = map(int,input().split())
        E[a-1][b-1] = c
        E[b-1][a-1] = c

     i 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 E[a-1][b-1] = c E[a-1][b-1] [a-1] E a-1 a 1 b-1 b 1 c E[b-1][a-1] = c E[b-1][a-1] [b-1] E b-1 b 1 a-1 a 1 c for k in range(n):
        for i in range(n):
            for j in range(n):
                E[i][j] = min(E[i][j],E[i][k]+E[k][j])
     k range(n) range n for i in range(n):
            for j in range(n):
                E[i][j] = min(E[i][j],E[i][k]+E[k][j])
     i range(n) range n for j in range(n):
                E[i][j] = min(E[i][j],E[i][k]+E[k][j])
     j range(n) range n E[i][j] = min(E[i][j],E[i][k]+E[k][j]) E[i][j] [i] E i j min(E[i][j],E[i][k]+E[k][j]) min 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 [float("INF")]*n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [float("INF")]*n [float("INF")] float("INF") float "INF" n wa = [[float("INF")]*n for i in range(n)] wa [[float("INF")]*n for i in range(n)] for i in range(n):
        for j in range(n):
            if E[i][j] <= l:
                wa[i][j] = 1
     i range(n) range n for j in range(n):
            if E[i][j] <= l:
                wa[i][j] = 1
     j range(n) range n if E[i][j] <= l:
                wa[i][j] = 1
     E[i][j] <= l E[i][j] [i] E i j l wa[i][j] = 1 wa[i][j] [i] wa i j 1 for k in range(n):
        for i in range(n):
            for j in range(n):
                wa[i][j] = min(wa[i][j],wa[i][k]+wa[k][j])
    
     k range(n) range n for i in range(n):
            for j in range(n):
                wa[i][j] = min(wa[i][j],wa[i][k]+wa[k][j])
    
     i range(n) range n for j in range(n):
                wa[i][j] = min(wa[i][j],wa[i][k]+wa[k][j])
    
     j range(n) range n wa[i][j] = min(wa[i][j],wa[i][k]+wa[k][j]) wa[i][j] [i] wa i j min(wa[i][j],wa[i][k]+wa[k][j]) min wa[i][j] [i] wa i j wa[i][k]+wa[k][j] wa[i][k] [i] wa i k wa[k][j] [k] wa k j x = int(input()) x int(input()) int input() input for i in range(x):
        s,g = map(int,input().split())
        if wa[s-1][g-1] == float("INF"):
            print(-1)
        else:
            print(wa[s-1][g-1]-1)

     i range(x) range x s,g = map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split g if wa[s-1][g-1] == float("INF"):
            print(-1)
        else:
            print(wa[s-1][g-1]-1)

     wa[s-1][g-1] == float("INF") wa[s-1][g-1] [s-1] wa s-1 s 1 g-1 g 1 float("INF") float "INF" print(-1) print -1 print(wa[s-1][g-1]-1) print wa[s-1][g-1]-1 wa[s-1][g-1] [s-1] wa s-1 s 1 g-1 g 1 1 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    import sys
    input = sys.stdin.readline
    n,m,l = map(int,input().split())
    E = [[float("INF")]*n for i in range(n)]
    for i in range(m):
        a,b,c = map(int,input().split())
        E[a-1][b-1] = c
        E[b-1][a-1] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                E[i][j] = min(E[i][j],E[i][k]+E[k][j])
    wa = [[float("INF")]*n for i in range(n)]
    for i in range(n):
        for j in range(n):
            if E[i][j] <= l:
                wa[i][j] = 1
    for k in range(n):
        for i in range(n):
            for j in range(n):
                wa[i][j] = min(wa[i][j],wa[i][k]+wa[k][j])
    
    x = int(input())
    for i in range(x):
        s,g = map(int,input().split())
        if wa[s-1][g-1] == float("INF"):
            print(-1)
        else:
            print(wa[s-1][g-1]-1)

     def main():
    import sys
    input = sys.stdin.readline
    n,m,l = map(int,input().split())
    E = [[float("INF")]*n for i in range(n)]
    for i in range(m):
        a,b,c = map(int,input().split())
        E[a-1][b-1] = c
        E[b-1][a-1] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                E[i][j] = min(E[i][j],E[i][k]+E[k][j])
    wa = [[float("INF")]*n for i in range(n)]
    for i in range(n):
        for j in range(n):
            if E[i][j] <= l:
                wa[i][j] = 1
    for k in range(n):
        for i in range(n):
            for j in range(n):
                wa[i][j] = min(wa[i][j],wa[i][k]+wa[k][j])
    
    x = int(input())
    for i in range(x):
        s,g = map(int,input().split())
        if wa[s-1][g-1] == float("INF"):
            print(-1)
        else:
            print(wa[s-1][g-1]-1)

     main
def main():
    import sys
    input = sys.stdin.readline
    n,m,l = map(int,input().split())
    E = [[float("INF")]*n for i in range(n)]
    for i in range(m):
        a,b,c = map(int,input().split())
        E[a-1][b-1] = c
        E[b-1][a-1] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                E[i][j] = min(E[i][j],E[i][k]+E[k][j])
    wa = [[float("INF")]*n for i in range(n)]
    for i in range(n):
        for j in range(n):
            if E[i][j] <= l:
                wa[i][j] = 1
    for k in range(n):
        for i in range(n):
            for j in range(n):
                wa[i][j] = min(wa[i][j],wa[i][k]+wa[k][j])
    
    x = int(input())
    for i in range(x):
        s,g = map(int,input().split())
        if wa[s-1][g-1] == float("INF"):
            print(-1)
        else:
            print(wa[s-1][g-1]-1)

    
if __name__ == "__main__":
    main()