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):
        u,v,w=map(int,input().split())
        if(w>L): continue
        u-=1; v-=1
        E[u].append((v,w))
        E[v].append((u,w))

    # 各始点からの Dijkstra
    # dist は (補給回数、補給してからの使用料)
    A=[None]*n
    for s in range(n):
        dist=[(INF,INF)]*n
        dist[s]=(0,0)
        used=[0]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not used[v]))[1]
            used[v]=1
            c,l=dist[v]
            for nv,w in E[v]:
                if(l+w>L):
                    nd=(c+1,w)
                else:
                    nd=(c,l+w)
                dist[nv]=min(dist[nv],nd)
        A[s]=dist

    for _ in range(int(input())):
        s,t=map(int,input().split())
        s-=1; t-=1
        res=A[s][t][0]
        print(res if(res!=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):
        u,v,w=map(int,input().split())
        if(w>L): continue
        u-=1; v-=1
        E[u].append((v,w))
        E[v].append((u,w))

    # 各始点からの Dijkstra
    # dist は (補給回数、補給してからの使用料)
    A=[None]*n
    for s in range(n):
        dist=[(INF,INF)]*n
        dist[s]=(0,0)
        used=[0]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not used[v]))[1]
            used[v]=1
            c,l=dist[v]
            for nv,w in E[v]:
                if(l+w>L):
                    nd=(c+1,w)
                else:
                    nd=(c,l+w)
                dist[nv]=min(dist[nv],nd)
        A[s]=dist

    for _ in range(int(input())):
        s,t=map(int,input().split())
        s-=1; t-=1
        res=A[s][t][0]
        print(res if(res!=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):
        u,v,w=map(int,input().split())
        if(w>L): continue
        u-=1; v-=1
        E[u].append((v,w))
        E[v].append((u,w))

    # 各始点からの Dijkstra
    # dist は (補給回数、補給してからの使用料)
     _ range(m) range m u,v,w=map(int,input().split()) u map(int,input().split()) map int input().split() ().split () input split v w if(w>L): continue
         w>L w L u-=1 u 1 v-=1 v 1 E[u].append((v,w)) [u].append [u] E u append (v,w) v w E[v].append((u,w)) [v].append [v] E v append (u,w) u w A=[None]*n A [None]*n [None] None n for s in range(n):
        dist=[(INF,INF)]*n
        dist[s]=(0,0)
        used=[0]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not used[v]))[1]
            used[v]=1
            c,l=dist[v]
            for nv,w in E[v]:
                if(l+w>L):
                    nd=(c+1,w)
                else:
                    nd=(c,l+w)
                dist[nv]=min(dist[nv],nd)
        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 used=[0]*n used [0]*n [0] 0 n for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not used[v]))[1]
            used[v]=1
            c,l=dist[v]
            for nv,w in E[v]:
                if(l+w>L):
                    nd=(c+1,w)
                else:
                    nd=(c,l+w)
                dist[nv]=min(dist[nv],nd)
         _ range(n-1) range n-1 n 1 v=min((dist[v],v) for v in range(n) if(not used[v]))[1] v min((dist[v],v) for v in range(n) if(not used[v]))[1] ((dist[v],v) for v in range(n) if(not used[v])) min (dist[v],v) dist[v] dist v v 1 used[v]=1 used[v] used v 1 c,l=dist[v] c dist[v] dist v l for nv,w in E[v]:
                if(l+w>L):
                    nd=(c+1,w)
                else:
                    nd=(c,l+w)
                dist[nv]=min(dist[nv],nd)
         nv w E[v] E v if(l+w>L):
                    nd=(c+1,w)
                else:
                    nd=(c,l+w)
                 l+w>L l+w l w L nd=(c+1,w) nd (c+1,w) c+1 c 1 w nd=(c,l+w) nd (c,l+w) c l+w l w dist[nv]=min(dist[nv],nd) dist[nv] dist nv min(dist[nv],nd) min dist[nv] dist nv nd A[s]=dist A[s] A s dist for _ in range(int(input())):
        s,t=map(int,input().split())
        s-=1; t-=1
        res=A[s][t][0]
        print(res if(res!=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 res=A[s][t][0] res A[s][t][0] [t] [s] A s t 0 print(res if(res!=INF) else -1) print res if(res!=INF) else -1 res!=INF res INF res -1 resolve() resolve input=lambda:sys.stdin.readline().rstrip() lambda:sys.stdin.readline().rstrip() input def resolve():
    n,m,L=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(m):
        u,v,w=map(int,input().split())
        if(w>L): continue
        u-=1; v-=1
        E[u].append((v,w))
        E[v].append((u,w))

    # 各始点からの Dijkstra
    # dist は (補給回数、補給してからの使用料)
    A=[None]*n
    for s in range(n):
        dist=[(INF,INF)]*n
        dist[s]=(0,0)
        used=[0]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not used[v]))[1]
            used[v]=1
            c,l=dist[v]
            for nv,w in E[v]:
                if(l+w>L):
                    nd=(c+1,w)
                else:
                    nd=(c,l+w)
                dist[nv]=min(dist[nv],nd)
        A[s]=dist

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

    # 各始点からの Dijkstra
    # dist は (補給回数、補給してからの使用料)
    A=[None]*n
    for s in range(n):
        dist=[(INF,INF)]*n
        dist[s]=(0,0)
        used=[0]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not used[v]))[1]
            used[v]=1
            c,l=dist[v]
            for nv,w in E[v]:
                if(l+w>L):
                    nd=(c+1,w)
                else:
                    nd=(c,l+w)
                dist[nv]=min(dist[nv],nd)
        A[s]=dist

    for _ in range(int(input())):
        s,t=map(int,input().split())
        s-=1; t-=1
        res=A[s][t][0]
        print(res if(res!=INF) else -1) resolve INF=float("inf") float("inf") INF MOD=10**9+7 10**9+7 MOD
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):
        u,v,w=map(int,input().split())
        if(w>L): continue
        u-=1; v-=1
        E[u].append((v,w))
        E[v].append((u,w))

    # 各始点からの Dijkstra
    # dist は (補給回数、補給してからの使用料)
    A=[None]*n
    for s in range(n):
        dist=[(INF,INF)]*n
        dist[s]=(0,0)
        used=[0]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not used[v]))[1]
            used[v]=1
            c,l=dist[v]
            for nv,w in E[v]:
                if(l+w>L):
                    nd=(c+1,w)
                else:
                    nd=(c,l+w)
                dist[nv]=min(dist[nv],nd)
        A[s]=dist

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