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))
    A=[0]*n
    # pure Dijkstraを全ての始点で行う
    for u in range(n):
        dist=[(INF,INF)]*n # (補給回数,使用燃料)
        dist[u]=(0,0)
        calculated=[False]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not calculated[v]))[1]
            calculated[v]=True
            now=dist[v]
            for nv,w in E[v]:
                if(now[1]+w<=L):
                    next=(now[0],now[1]+w)
                else:
                    next=(now[0]+1,w)
                if(dist[nv]>next):
                    dist[nv]=next
        A[u]=dist
    # output
    Q=int(input())
    for _ in range(Q):
        s,t=map(int,input().split())
        s-=1; t-=1
        ans=A[s][t][0]
        print(ans if ans!=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))
    A=[0]*n
    # pure Dijkstraを全ての始点で行う
    for u in range(n):
        dist=[(INF,INF)]*n # (補給回数,使用燃料)
        dist[u]=(0,0)
        calculated=[False]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not calculated[v]))[1]
            calculated[v]=True
            now=dist[v]
            for nv,w in E[v]:
                if(now[1]+w<=L):
                    next=(now[0],now[1]+w)
                else:
                    next=(now[0]+1,w)
                if(dist[nv]>next):
                    dist[nv]=next
        A[u]=dist
    # output
    Q=int(input())
    for _ in range(Q):
        s,t=map(int,input().split())
        s-=1; t-=1
        ans=A[s][t][0]
        print(ans if ans!=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))
     _ 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=[0]*n A [0]*n [0] 0 n for u in range(n):
        dist=[(INF,INF)]*n # (補給回数,使用燃料)
        dist[u]=(0,0)
        calculated=[False]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not calculated[v]))[1]
            calculated[v]=True
            now=dist[v]
            for nv,w in E[v]:
                if(now[1]+w<=L):
                    next=(now[0],now[1]+w)
                else:
                    next=(now[0]+1,w)
                if(dist[nv]>next):
                    dist[nv]=next
        A[u]=dist
    # output
     u range(n) range n dist=[(INF,INF)]*n dist [(INF,INF)]*n [(INF,INF)] (INF,INF) INF INF n dist[u]=(0,0) dist[u] dist u (0,0) 0 0 calculated=[False]*n calculated [False]*n [False] False n for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not calculated[v]))[1]
            calculated[v]=True
            now=dist[v]
            for nv,w in E[v]:
                if(now[1]+w<=L):
                    next=(now[0],now[1]+w)
                else:
                    next=(now[0]+1,w)
                if(dist[nv]>next):
                    dist[nv]=next
         _ range(n-1) range n-1 n 1 v=min((dist[v],v) for v in range(n) if(not calculated[v]))[1] v min((dist[v],v) for v in range(n) if(not calculated[v]))[1] ((dist[v],v) for v in range(n) if(not calculated[v])) min (dist[v],v) dist[v] dist v v 1 calculated[v]=True calculated[v] calculated v True now=dist[v] now dist[v] dist v for nv,w in E[v]:
                if(now[1]+w<=L):
                    next=(now[0],now[1]+w)
                else:
                    next=(now[0]+1,w)
                if(dist[nv]>next):
                    dist[nv]=next
         nv w E[v] E v if(now[1]+w<=L):
                    next=(now[0],now[1]+w)
                else:
                    next=(now[0]+1,w)
                 now[1]+w<=L now[1]+w now[1] now 1 w L next=(now[0],now[1]+w) next (now[0],now[1]+w) now[0] now 0 now[1]+w now[1] now 1 w next=(now[0]+1,w) next (now[0]+1,w) now[0]+1 now[0] now 0 1 w if(dist[nv]>next):
                    dist[nv]=next
         dist[nv]>next dist[nv] dist nv next dist[nv]=next dist[nv] dist nv next A[u]=dist A[u] A u dist Q=int(input()) Q int(input()) int input() input for _ in range(Q):
        s,t=map(int,input().split())
        s-=1; t-=1
        ans=A[s][t][0]
        print(ans if ans!=INF else -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=A[s][t][0] ans A[s][t][0] [t] [s] A s t 0 print(ans if ans!=INF else -1) print ans if ans!=INF else -1 ans!=INF ans INF ans -1 resolve() resolve 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))
    A=[0]*n
    # pure Dijkstraを全ての始点で行う
    for u in range(n):
        dist=[(INF,INF)]*n # (補給回数,使用燃料)
        dist[u]=(0,0)
        calculated=[False]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not calculated[v]))[1]
            calculated[v]=True
            now=dist[v]
            for nv,w in E[v]:
                if(now[1]+w<=L):
                    next=(now[0],now[1]+w)
                else:
                    next=(now[0]+1,w)
                if(dist[nv]>next):
                    dist[nv]=next
        A[u]=dist
    # output
    Q=int(input())
    for _ in range(Q):
        s,t=map(int,input().split())
        s-=1; t-=1
        ans=A[s][t][0]
        print(ans if ans!=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))
    A=[0]*n
    # pure Dijkstraを全ての始点で行う
    for u in range(n):
        dist=[(INF,INF)]*n # (補給回数,使用燃料)
        dist[u]=(0,0)
        calculated=[False]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not calculated[v]))[1]
            calculated[v]=True
            now=dist[v]
            for nv,w in E[v]:
                if(now[1]+w<=L):
                    next=(now[0],now[1]+w)
                else:
                    next=(now[0]+1,w)
                if(dist[nv]>next):
                    dist[nv]=next
        A[u]=dist
    # output
    Q=int(input())
    for _ in range(Q):
        s,t=map(int,input().split())
        s-=1; t-=1
        ans=A[s][t][0]
        print(ans if ans!=INF else -1) resolve input=lambda :sys.stdin.readline().rstrip() lambda :sys.stdin.readline().rstrip() input
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))
    A=[0]*n
    # pure Dijkstraを全ての始点で行う
    for u in range(n):
        dist=[(INF,INF)]*n # (補給回数,使用燃料)
        dist[u]=(0,0)
        calculated=[False]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not calculated[v]))[1]
            calculated[v]=True
            now=dist[v]
            for nv,w in E[v]:
                if(now[1]+w<=L):
                    next=(now[0],now[1]+w)
                else:
                    next=(now[0]+1,w)
                if(dist[nv]>next):
                    dist[nv]=next
        A[u]=dist
    # output
    Q=int(input())
    for _ in range(Q):
        s,t=map(int,input().split())
        s-=1; t-=1
        ans=A[s][t][0]
        print(ans if ans!=INF else -1)
resolve()