import sys
def main():
    input=sys.stdin.readline
    n,m,l=map(int,input().split())
    edge=[[] for i in range(n)]
    for _ in range(m):
        a,b,c=map(int,input().split())
        if c>l:
            continue
        a-=1
        b-=1
        edge[a].append((c,b))
        edge[b].append((c,a))
    def dijkstra(s):
        used=[False for _ in range(n)]
        dist=[(10**18,10**18) for _ in range(n)]
        dist[s]=(0,0)
        for _ in range(n):
            (time,cons),x=min([(dist[i],i) for i in range(n) if not used[i]])
            used[x]=True
            for cost,nx in edge[x]:
                ntime,ncons=dist[nx]
                if l-cons>=cost:
                    if ntime>time:
                        dist[nx]=(time,cons+cost)
                    elif ntime==time:
                        if ncons>cons+cost:
                            dist[nx]=(time,cons+cost)
                else:
                    if ntime>time+1:
                        dist[nx]=(time+1,cost)
                    elif ntime==time+1:
                        if ncons>cost:
                            dist[nx]=(ntime,cost)
        return dist
    ans=[]
    #print(edge)
    for s in range(n):
        ans.append(dijkstra(s))
    q=int(input())
    for _ in range(q):
        s,t=map(int,input().split())
        s-=1
        t-=1
        if ans[s][t][0]==10**18:
            print(-1)
        else:
            print(ans[s][t][0])
if __name__=="__main__":
  main() import sys sys def main():
    input=sys.stdin.readline
    n,m,l=map(int,input().split())
    edge=[[] for i in range(n)]
    for _ in range(m):
        a,b,c=map(int,input().split())
        if c>l:
            continue
        a-=1
        b-=1
        edge[a].append((c,b))
        edge[b].append((c,a))
    def dijkstra(s):
        used=[False for _ in range(n)]
        dist=[(10**18,10**18) for _ in range(n)]
        dist[s]=(0,0)
        for _ in range(n):
            (time,cons),x=min([(dist[i],i) for i in range(n) if not used[i]])
            used[x]=True
            for cost,nx in edge[x]:
                ntime,ncons=dist[nx]
                if l-cons>=cost:
                    if ntime>time:
                        dist[nx]=(time,cons+cost)
                    elif ntime==time:
                        if ncons>cons+cost:
                            dist[nx]=(time,cons+cost)
                else:
                    if ntime>time+1:
                        dist[nx]=(time+1,cost)
                    elif ntime==time+1:
                        if ncons>cost:
                            dist[nx]=(ntime,cost)
        return dist
    ans=[]
    #print(edge)
    for s in range(n):
        ans.append(dijkstra(s))
    q=int(input())
    for _ in range(q):
        s,t=map(int,input().split())
        s-=1
        t-=1
        if ans[s][t][0]==10**18:
            print(-1)
        else:
            print(ans[s][t][0]) main 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 [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] edge=[[] for i in range(n)] edge [[] for i in range(n)] for _ in range(m):
        a,b,c=map(int,input().split())
        if c>l:
            continue
        a-=1
        b-=1
        edge[a].append((c,b))
        edge[b].append((c,a))
     _ 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 continue a-=1 a 1 b-=1 b 1 edge[a].append((c,b)) [a].append [a] edge a append (c,b) c b edge[b].append((c,a)) [b].append [b] edge b append (c,a) c a def dijkstra(s):
        used=[False for _ in range(n)]
        dist=[(10**18,10**18) for _ in range(n)]
        dist[s]=(0,0)
        for _ in range(n):
            (time,cons),x=min([(dist[i],i) for i in range(n) if not used[i]])
            used[x]=True
            for cost,nx in edge[x]:
                ntime,ncons=dist[nx]
                if l-cons>=cost:
                    if ntime>time:
                        dist[nx]=(time,cons+cost)
                    elif ntime==time:
                        if ncons>cons+cost:
                            dist[nx]=(time,cons+cost)
                else:
                    if ntime>time+1:
                        dist[nx]=(time+1,cost)
                    elif ntime==time+1:
                        if ncons>cost:
                            dist[nx]=(ntime,cost)
        return dist
     dijkstra False for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) False used=[False for _ in range(n)] used [False for _ in range(n)] (10**18,10**18) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) (10**18,10**18) 10**18 10 18 10**18 10 18 dist=[(10**18,10**18) for _ in range(n)] dist [(10**18,10**18) for _ in range(n)] dist[s]=(0,0) dist[s] dist s (0,0) 0 0 for _ in range(n):
            (time,cons),x=min([(dist[i],i) for i in range(n) if not used[i]])
            used[x]=True
            for cost,nx in edge[x]:
                ntime,ncons=dist[nx]
                if l-cons>=cost:
                    if ntime>time:
                        dist[nx]=(time,cons+cost)
                    elif ntime==time:
                        if ncons>cons+cost:
                            dist[nx]=(time,cons+cost)
                else:
                    if ntime>time+1:
                        dist[nx]=(time+1,cost)
                    elif ntime==time+1:
                        if ncons>cost:
                            dist[nx]=(ntime,cost)
         _ range(n) range n (dist[i],i) for i in range(n) if not used[i] for i in range(n) if not used[i] i range(n) range n not used[i] used[i] used i if not used[i] (dist[i],i) dist[i] dist i i (time,cons),x=min([(dist[i],i) for i in range(n) if not used[i]]) (time,cons) time cons min([(dist[i],i) for i in range(n) if not used[i]]) min [(dist[i],i) for i in range(n) if not used[i]] x used[x]=True used[x] used x True for cost,nx in edge[x]:
                ntime,ncons=dist[nx]
                if l-cons>=cost:
                    if ntime>time:
                        dist[nx]=(time,cons+cost)
                    elif ntime==time:
                        if ncons>cons+cost:
                            dist[nx]=(time,cons+cost)
                else:
                    if ntime>time+1:
                        dist[nx]=(time+1,cost)
                    elif ntime==time+1:
                        if ncons>cost:
                            dist[nx]=(ntime,cost)
         cost nx edge[x] edge x ntime,ncons=dist[nx] ntime dist[nx] dist nx ncons if l-cons>=cost:
                    if ntime>time:
                        dist[nx]=(time,cons+cost)
                    elif ntime==time:
                        if ncons>cons+cost:
                            dist[nx]=(time,cons+cost)
                else:
                    if ntime>time+1:
                        dist[nx]=(time+1,cost)
                    elif ntime==time+1:
                        if ncons>cost:
                            dist[nx]=(ntime,cost)
         l-cons>=cost l-cons l cons cost if ntime>time:
                        dist[nx]=(time,cons+cost)
                    elif ntime==time:
                        if ncons>cons+cost:
                            dist[nx]=(time,cons+cost)
                 ntime>time ntime time dist[nx]=(time,cons+cost) dist[nx] dist nx (time,cons+cost) time cons+cost cons cost elif ntime==time:
                        if ncons>cons+cost:
                            dist[nx]=(time,cons+cost)
                 ntime==time ntime time if ncons>cons+cost:
                            dist[nx]=(time,cons+cost)
                 ncons>cons+cost ncons cons+cost cons cost dist[nx]=(time,cons+cost) dist[nx] dist nx (time,cons+cost) time cons+cost cons cost if ntime>time+1:
                        dist[nx]=(time+1,cost)
                    elif ntime==time+1:
                        if ncons>cost:
                            dist[nx]=(ntime,cost)
         ntime>time+1 ntime time+1 time 1 dist[nx]=(time+1,cost) dist[nx] dist nx (time+1,cost) time+1 time 1 cost elif ntime==time+1:
                        if ncons>cost:
                            dist[nx]=(ntime,cost)
         ntime==time+1 ntime time+1 time 1 if ncons>cost:
                            dist[nx]=(ntime,cost)
         ncons>cost ncons cost dist[nx]=(ntime,cost) dist[nx] dist nx (ntime,cost) ntime cost return dist dist s s ans=[] ans [] for s in range(n):
        ans.append(dijkstra(s))
     s range(n) range n ans.append(dijkstra(s)) ans.append ans append dijkstra(s) dijkstra s q=int(input()) q int(input()) int input() input for _ in range(q):
        s,t=map(int,input().split())
        s-=1
        t-=1
        if ans[s][t][0]==10**18:
            print(-1)
        else:
            print(ans[s][t][0]) _ 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 if ans[s][t][0]==10**18:
            print(-1)
        else:
            print(ans[s][t][0]) ans[s][t][0]==10**18 ans[s][t][0] [t] [s] ans s t 0 10**18 10 18 print(-1) print -1 print(ans[s][t][0]) print ans[s][t][0] [t] [s] ans s t 0 if __name__=="__main__":
  main() __name__=="__main__" __name__ "__main__" main() main def main():
    input=sys.stdin.readline
    n,m,l=map(int,input().split())
    edge=[[] for i in range(n)]
    for _ in range(m):
        a,b,c=map(int,input().split())
        if c>l:
            continue
        a-=1
        b-=1
        edge[a].append((c,b))
        edge[b].append((c,a))
    def dijkstra(s):
        used=[False for _ in range(n)]
        dist=[(10**18,10**18) for _ in range(n)]
        dist[s]=(0,0)
        for _ in range(n):
            (time,cons),x=min([(dist[i],i) for i in range(n) if not used[i]])
            used[x]=True
            for cost,nx in edge[x]:
                ntime,ncons=dist[nx]
                if l-cons>=cost:
                    if ntime>time:
                        dist[nx]=(time,cons+cost)
                    elif ntime==time:
                        if ncons>cons+cost:
                            dist[nx]=(time,cons+cost)
                else:
                    if ntime>time+1:
                        dist[nx]=(time+1,cost)
                    elif ntime==time+1:
                        if ncons>cost:
                            dist[nx]=(ntime,cost)
        return dist
    ans=[]
    #print(edge)
    for s in range(n):
        ans.append(dijkstra(s))
    q=int(input())
    for _ in range(q):
        s,t=map(int,input().split())
        s-=1
        t-=1
        if ans[s][t][0]==10**18:
            print(-1)
        else:
            print(ans[s][t][0]) def main():
    input=sys.stdin.readline
    n,m,l=map(int,input().split())
    edge=[[] for i in range(n)]
    for _ in range(m):
        a,b,c=map(int,input().split())
        if c>l:
            continue
        a-=1
        b-=1
        edge[a].append((c,b))
        edge[b].append((c,a))
    def dijkstra(s):
        used=[False for _ in range(n)]
        dist=[(10**18,10**18) for _ in range(n)]
        dist[s]=(0,0)
        for _ in range(n):
            (time,cons),x=min([(dist[i],i) for i in range(n) if not used[i]])
            used[x]=True
            for cost,nx in edge[x]:
                ntime,ncons=dist[nx]
                if l-cons>=cost:
                    if ntime>time:
                        dist[nx]=(time,cons+cost)
                    elif ntime==time:
                        if ncons>cons+cost:
                            dist[nx]=(time,cons+cost)
                else:
                    if ntime>time+1:
                        dist[nx]=(time+1,cost)
                    elif ntime==time+1:
                        if ncons>cost:
                            dist[nx]=(ntime,cost)
        return dist
    ans=[]
    #print(edge)
    for s in range(n):
        ans.append(dijkstra(s))
    q=int(input())
    for _ in range(q):
        s,t=map(int,input().split())
        s-=1
        t-=1
        if ans[s][t][0]==10**18:
            print(-1)
        else:
            print(ans[s][t][0]) main
import sys
def main():
    input=sys.stdin.readline
    n,m,l=map(int,input().split())
    edge=[[] for i in range(n)]
    for _ in range(m):
        a,b,c=map(int,input().split())
        if c>l:
            continue
        a-=1
        b-=1
        edge[a].append((c,b))
        edge[b].append((c,a))
    def dijkstra(s):
        used=[False for _ in range(n)]
        dist=[(10**18,10**18) for _ in range(n)]
        dist[s]=(0,0)
        for _ in range(n):
            (time,cons),x=min([(dist[i],i) for i in range(n) if not used[i]])
            used[x]=True
            for cost,nx in edge[x]:
                ntime,ncons=dist[nx]
                if l-cons>=cost:
                    if ntime>time:
                        dist[nx]=(time,cons+cost)
                    elif ntime==time:
                        if ncons>cons+cost:
                            dist[nx]=(time,cons+cost)
                else:
                    if ntime>time+1:
                        dist[nx]=(time+1,cost)
                    elif ntime==time+1:
                        if ncons>cost:
                            dist[nx]=(ntime,cost)
        return dist
    ans=[]
    #print(edge)
    for s in range(n):
        ans.append(dijkstra(s))
    q=int(input())
    for _ in range(q):
        s,t=map(int,input().split())
        s-=1
        t-=1
        if ans[s][t][0]==10**18:
            print(-1)
        else:
            print(ans[s][t][0])
if __name__=="__main__":
  main()