import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,m,l=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(m):
        a,b,c=map(int,input().split())
        if(c>l): continue
        a-=1; b-=1
        E[a].append((b,c))
        E[b].append((a,c))

    # 各頂点を始点としたDijkstra
    A=[None]*n
    for s in range(n):
        dist=[(INF,INF)]*n
        dist[s]=(0,0)
        visited=[0]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not visited[v]))[1]
            visited[v]=1
            for nv,w in E[v]:
                a,b=dist[v]
                if(b+w<=l): na,nb=a,b+w
                else: na,nb=a+1,w
                if(dist[nv]>(na,nb)):
                    dist[nv]=(na,nb)
        A[s]=dist

    for _ in range(int(input())):
        s,t=map(int,input().split())
        s-=1; t-=1
        print(A[s][t][0] if(A[s][t][0]!=INF) else -1)
resolve() import sys sys sys.setrecursionlimit(2147483647) sys.setrecursionlimit sys setrecursionlimit 2147483647 INF=float("inf") INF float("inf") float "inf" MOD=10**9+7 MOD 10**9+7 10**9 10 9 7 input=lambda:sys.stdin.readline().rstrip() input lambda: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 resolve():
    n,m,l=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(m):
        a,b,c=map(int,input().split())
        if(c>l): continue
        a-=1; b-=1
        E[a].append((b,c))
        E[b].append((a,c))

    # 各頂点を始点としたDijkstra
    A=[None]*n
    for s in range(n):
        dist=[(INF,INF)]*n
        dist[s]=(0,0)
        visited=[0]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not visited[v]))[1]
            visited[v]=1
            for nv,w in E[v]:
                a,b=dist[v]
                if(b+w<=l): na,nb=a,b+w
                else: na,nb=a+1,w
                if(dist[nv]>(na,nb)):
                    dist[nv]=(na,nb)
        A[s]=dist

    for _ in range(int(input())):
        s,t=map(int,input().split())
        s-=1; t-=1
        print(A[s][t][0] if(A[s][t][0]!=INF) else -1) resolve n,m,l=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] E=[[] for _ in range(n)] E [[] for _ in range(n)] for _ in range(m):
        a,b,c=map(int,input().split())
        if(c>l): continue
        a-=1; b-=1
        E[a].append((b,c))
        E[b].append((a,c))

    # 各頂点を始点としたDijkstra
     _ 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 if(c>l): continue
         c>l c l a-=1 a 1 b-=1 b 1 E[a].append((b,c)) [a].append [a] E a append (b,c) b c E[b].append((a,c)) [b].append [b] E b append (a,c) a c A=[None]*n A [None]*n [None] None n for s in range(n):
        dist=[(INF,INF)]*n
        dist[s]=(0,0)
        visited=[0]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not visited[v]))[1]
            visited[v]=1
            for nv,w in E[v]:
                a,b=dist[v]
                if(b+w<=l): na,nb=a,b+w
                else: na,nb=a+1,w
                if(dist[nv]>(na,nb)):
                    dist[nv]=(na,nb)
        A[s]=dist

     s range(n) range n dist=[(INF,INF)]*n dist [(INF,INF)]*n [(INF,INF)] (INF,INF) INF INF n dist[s]=(0,0) dist[s] dist s (0,0) 0 0 visited=[0]*n visited [0]*n [0] 0 n for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not visited[v]))[1]
            visited[v]=1
            for nv,w in E[v]:
                a,b=dist[v]
                if(b+w<=l): na,nb=a,b+w
                else: na,nb=a+1,w
                if(dist[nv]>(na,nb)):
                    dist[nv]=(na,nb)
         _ range(n-1) range n-1 n 1 v=min((dist[v],v) for v in range(n) if(not visited[v]))[1] v min((dist[v],v) for v in range(n) if(not visited[v]))[1] ((dist[v],v) for v in range(n) if(not visited[v])) min (dist[v],v) dist[v] dist v v 1 visited[v]=1 visited[v] visited v 1 for nv,w in E[v]:
                a,b=dist[v]
                if(b+w<=l): na,nb=a,b+w
                else: na,nb=a+1,w
                if(dist[nv]>(na,nb)):
                    dist[nv]=(na,nb)
         nv w E[v] E v a,b=dist[v] a dist[v] dist v b if(b+w<=l): na,nb=a,b+w
                else: na,nb=a+1,w
                 b+w<=l b+w b w l if(dist[nv]>(na,nb)):
                    dist[nv]=(na,nb)
         dist[nv]>(na,nb) dist[nv] dist nv (na,nb) na nb dist[nv]=(na,nb) dist[nv] dist nv (na,nb) na nb A[s]=dist A[s] A s dist for _ in range(int(input())):
        s,t=map(int,input().split())
        s-=1; t-=1
        print(A[s][t][0] if(A[s][t][0]!=INF) else -1) _ range(int(input())) range int(input()) int input() input 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 print(A[s][t][0] if(A[s][t][0]!=INF) else -1) print A[s][t][0] if(A[s][t][0]!=INF) else -1 A[s][t][0]!=INF A[s][t][0] [t] [s] A s t 0 INF A[s][t][0] [t] [s] A s t 0 -1 resolve() resolve input=lambda:sys.stdin.readline().rstrip() lambda:sys.stdin.readline().rstrip() input INF=float("inf") float("inf") INF MOD=10**9+7 10**9+7 MOD def resolve():
    n,m,l=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(m):
        a,b,c=map(int,input().split())
        if(c>l): continue
        a-=1; b-=1
        E[a].append((b,c))
        E[b].append((a,c))

    # 各頂点を始点としたDijkstra
    A=[None]*n
    for s in range(n):
        dist=[(INF,INF)]*n
        dist[s]=(0,0)
        visited=[0]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not visited[v]))[1]
            visited[v]=1
            for nv,w in E[v]:
                a,b=dist[v]
                if(b+w<=l): na,nb=a,b+w
                else: na,nb=a+1,w
                if(dist[nv]>(na,nb)):
                    dist[nv]=(na,nb)
        A[s]=dist

    for _ in range(int(input())):
        s,t=map(int,input().split())
        s-=1; t-=1
        print(A[s][t][0] if(A[s][t][0]!=INF) else -1) def resolve():
    n,m,l=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(m):
        a,b,c=map(int,input().split())
        if(c>l): continue
        a-=1; b-=1
        E[a].append((b,c))
        E[b].append((a,c))

    # 各頂点を始点としたDijkstra
    A=[None]*n
    for s in range(n):
        dist=[(INF,INF)]*n
        dist[s]=(0,0)
        visited=[0]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not visited[v]))[1]
            visited[v]=1
            for nv,w in E[v]:
                a,b=dist[v]
                if(b+w<=l): na,nb=a,b+w
                else: na,nb=a+1,w
                if(dist[nv]>(na,nb)):
                    dist[nv]=(na,nb)
        A[s]=dist

    for _ in range(int(input())):
        s,t=map(int,input().split())
        s-=1; t-=1
        print(A[s][t][0] if(A[s][t][0]!=INF) else -1) resolve
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,m,l=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(m):
        a,b,c=map(int,input().split())
        if(c>l): continue
        a-=1; b-=1
        E[a].append((b,c))
        E[b].append((a,c))

    # 各頂点を始点としたDijkstra
    A=[None]*n
    for s in range(n):
        dist=[(INF,INF)]*n
        dist[s]=(0,0)
        visited=[0]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not visited[v]))[1]
            visited[v]=1
            for nv,w in E[v]:
                a,b=dist[v]
                if(b+w<=l): na,nb=a,b+w
                else: na,nb=a+1,w
                if(dist[nv]>(na,nb)):
                    dist[nv]=(na,nb)
        A[s]=dist

    for _ in range(int(input())):
        s,t=map(int,input().split())
        s-=1; t-=1
        print(A[s][t][0] if(A[s][t][0]!=INF) else -1)
resolve()