import sys
from heapq import heappop, heappush
from scipy.sparse.csgraph import floyd_warshall
input = sys.stdin.readline
 
def main():
    n,w,l = map(int,input().split())
    d = [[10**15 for _ in range(n)] for _ in range(n)]
    for _ in range(w):
        x,y,z = map(int,input().split())
        x -= 1
        y -= 1
        if z > l:
            continue
        d[x][y] = z
        d[y][x] = z
    for i in range(n):
        d[i][i] = 0
    d = floyd_warshall(d)
    G = [[10**15 for _ in range(n)] for _ in range(n)]
    for i in range(n-1):
        for j in range(i+1,n):
            if d[i][j] <= l:
                G[i][j] = 1
                G[j][i] = 1
    for i in range(n):
        G[i][i] = 0
    G = floyd_warshall(G)
    q = int(input())
    for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        ans = G[s][t]
        if ans == 10**15:
            print(-1)
            continue
        print(int(ans)-1)
    
if __name__ == "__main__":
    main() import sys sys from heapq import heappop, heappush from scipy.sparse.csgraph import floyd_warshall input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def main():
    n,w,l = map(int,input().split())
    d = [[10**15 for _ in range(n)] for _ in range(n)]
    for _ in range(w):
        x,y,z = map(int,input().split())
        x -= 1
        y -= 1
        if z > l:
            continue
        d[x][y] = z
        d[y][x] = z
    for i in range(n):
        d[i][i] = 0
    d = floyd_warshall(d)
    G = [[10**15 for _ in range(n)] for _ in range(n)]
    for i in range(n-1):
        for j in range(i+1,n):
            if d[i][j] <= l:
                G[i][j] = 1
                G[j][i] = 1
    for i in range(n):
        G[i][i] = 0
    G = floyd_warshall(G)
    q = int(input())
    for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        ans = G[s][t]
        if ans == 10**15:
            print(-1)
            continue
        print(int(ans)-1)
     main n,w,l = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split w l [10**15 for _ in range(n)] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [10**15 for _ in range(n)] d = [[10**15 for _ in range(n)] for _ in range(n)] d [[10**15 for _ in range(n)] for _ in range(n)] for _ in range(w):
        x,y,z = map(int,input().split())
        x -= 1
        y -= 1
        if z > l:
            continue
        d[x][y] = z
        d[y][x] = z
     _ range(w) range w x,y,z = map(int,input().split()) x map(int,input().split()) map int input().split() ().split () input split y z x -= 1 x 1 y -= 1 y 1 if z > l:
            continue
         z > l z l continue d[x][y] = z d[x][y] [x] d x y z d[y][x] = z d[y][x] [y] d y x z for i in range(n):
        d[i][i] = 0
     i range(n) range n d[i][i] = 0 d[i][i] [i] d i i 0 d = floyd_warshall(d) d floyd_warshall(d) floyd_warshall d [10**15 for _ in range(n)] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [10**15 for _ in range(n)] G = [[10**15 for _ in range(n)] for _ in range(n)] G [[10**15 for _ in range(n)] for _ in range(n)] for i in range(n-1):
        for j in range(i+1,n):
            if d[i][j] <= l:
                G[i][j] = 1
                G[j][i] = 1
     i range(n-1) range n-1 n 1 for j in range(i+1,n):
            if d[i][j] <= l:
                G[i][j] = 1
                G[j][i] = 1
     j range(i+1,n) range i+1 i 1 n if d[i][j] <= l:
                G[i][j] = 1
                G[j][i] = 1
     d[i][j] <= l d[i][j] [i] d i j l G[i][j] = 1 G[i][j] [i] G i j 1 G[j][i] = 1 G[j][i] [j] G j i 1 for i in range(n):
        G[i][i] = 0
     i range(n) range n G[i][i] = 0 G[i][i] [i] G i i 0 G = floyd_warshall(G) G floyd_warshall(G) floyd_warshall G q = int(input()) q int(input()) int input() input for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        ans = G[s][t]
        if ans == 10**15:
            print(-1)
            continue
        print(int(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 ans = G[s][t] ans G[s][t] [s] G s t if ans == 10**15:
            print(-1)
            continue
         ans == 10**15 ans 10**15 10 15 print(-1) print -1 continue print(int(ans)-1) print int(ans)-1 int(ans) int ans 1 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    n,w,l = map(int,input().split())
    d = [[10**15 for _ in range(n)] for _ in range(n)]
    for _ in range(w):
        x,y,z = map(int,input().split())
        x -= 1
        y -= 1
        if z > l:
            continue
        d[x][y] = z
        d[y][x] = z
    for i in range(n):
        d[i][i] = 0
    d = floyd_warshall(d)
    G = [[10**15 for _ in range(n)] for _ in range(n)]
    for i in range(n-1):
        for j in range(i+1,n):
            if d[i][j] <= l:
                G[i][j] = 1
                G[j][i] = 1
    for i in range(n):
        G[i][i] = 0
    G = floyd_warshall(G)
    q = int(input())
    for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        ans = G[s][t]
        if ans == 10**15:
            print(-1)
            continue
        print(int(ans)-1)
     def main():
    n,w,l = map(int,input().split())
    d = [[10**15 for _ in range(n)] for _ in range(n)]
    for _ in range(w):
        x,y,z = map(int,input().split())
        x -= 1
        y -= 1
        if z > l:
            continue
        d[x][y] = z
        d[y][x] = z
    for i in range(n):
        d[i][i] = 0
    d = floyd_warshall(d)
    G = [[10**15 for _ in range(n)] for _ in range(n)]
    for i in range(n-1):
        for j in range(i+1,n):
            if d[i][j] <= l:
                G[i][j] = 1
                G[j][i] = 1
    for i in range(n):
        G[i][i] = 0
    G = floyd_warshall(G)
    q = int(input())
    for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        ans = G[s][t]
        if ans == 10**15:
            print(-1)
            continue
        print(int(ans)-1)
     main input = sys.stdin.readline sys.stdin.readline input
import sys
from heapq import heappop, heappush
from scipy.sparse.csgraph import floyd_warshall
input = sys.stdin.readline
 
def main():
    n,w,l = map(int,input().split())
    d = [[10**15 for _ in range(n)] for _ in range(n)]
    for _ in range(w):
        x,y,z = map(int,input().split())
        x -= 1
        y -= 1
        if z > l:
            continue
        d[x][y] = z
        d[y][x] = z
    for i in range(n):
        d[i][i] = 0
    d = floyd_warshall(d)
    G = [[10**15 for _ in range(n)] for _ in range(n)]
    for i in range(n-1):
        for j in range(i+1,n):
            if d[i][j] <= l:
                G[i][j] = 1
                G[j][i] = 1
    for i in range(n):
        G[i][i] = 0
    G = floyd_warshall(G)
    q = int(input())
    for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        ans = G[s][t]
        if ans == 10**15:
            print(-1)
            continue
        print(int(ans)-1)
    
if __name__ == "__main__":
    main()