def solve():
    INF = float('inf')

    def Dijkstra(adjList, vSt):
        numV = len(adjList)
        useds = [False] * numV
        fuels = [-1] * numV
        fuels[vSt] = L
        nums = [INF] * numV
        num = 0
        vs = set([vSt])
        while vs:
            vNexts = set()
            fuelNexts = [-1] * numV
            while vs:
                fNow, vNow = -1, -1
                for v in vs:
                    if fuels[v] > fNow:
                        fNow, vNow = fuels[v], v
                nums[vNow] = num
                useds[vNow] = True
                vs.remove(vNow)

                fuel = fuels[vNow]
                for v2, wt in adjList[vNow]:
                    if useds[v2]: continue
                    if fuel >= wt:
                        if fuel-wt > fuels[v2]:
                            fuels[v2] = fuel-wt
                        vs.add(v2)
                    elif L >= wt:
                        if L-wt > fuelNexts[v2]:
                            fuelNexts[v2] = L-wt
                        vNexts.add(v2)

            vs = set([v for v in vNexts if not useds[v]])
            fuels = fuelNexts
            num += 1
        return nums


    N, M, L = map(int, input().split())
    adjL = [[] for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        A, B = A-1, B-1
        adjL[A].append((B, C))
        adjL[B].append((A, C))

    numss = []
    for v in range(N):
        nums = Dijkstra(adjL, v)
        numss.append(nums)

    Q = int(input())
    anss = []
    for _ in range(Q):
        s, t = map(int, input().split())
        s, t = s-1, t-1
        if numss[s][t] == INF:
            anss.append(-1)
        else:
            anss.append(numss[s][t])

    print('\n'.join(map(str, anss)))


solve() def solve():
    INF = float('inf')

    def Dijkstra(adjList, vSt):
        numV = len(adjList)
        useds = [False] * numV
        fuels = [-1] * numV
        fuels[vSt] = L
        nums = [INF] * numV
        num = 0
        vs = set([vSt])
        while vs:
            vNexts = set()
            fuelNexts = [-1] * numV
            while vs:
                fNow, vNow = -1, -1
                for v in vs:
                    if fuels[v] > fNow:
                        fNow, vNow = fuels[v], v
                nums[vNow] = num
                useds[vNow] = True
                vs.remove(vNow)

                fuel = fuels[vNow]
                for v2, wt in adjList[vNow]:
                    if useds[v2]: continue
                    if fuel >= wt:
                        if fuel-wt > fuels[v2]:
                            fuels[v2] = fuel-wt
                        vs.add(v2)
                    elif L >= wt:
                        if L-wt > fuelNexts[v2]:
                            fuelNexts[v2] = L-wt
                        vNexts.add(v2)

            vs = set([v for v in vNexts if not useds[v]])
            fuels = fuelNexts
            num += 1
        return nums


    N, M, L = map(int, input().split())
    adjL = [[] for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        A, B = A-1, B-1
        adjL[A].append((B, C))
        adjL[B].append((A, C))

    numss = []
    for v in range(N):
        nums = Dijkstra(adjL, v)
        numss.append(nums)

    Q = int(input())
    anss = []
    for _ in range(Q):
        s, t = map(int, input().split())
        s, t = s-1, t-1
        if numss[s][t] == INF:
            anss.append(-1)
        else:
            anss.append(numss[s][t])

    print('\n'.join(map(str, anss))) solve INF = float('inf') INF float('inf') float 'inf' def Dijkstra(adjList, vSt):
        numV = len(adjList)
        useds = [False] * numV
        fuels = [-1] * numV
        fuels[vSt] = L
        nums = [INF] * numV
        num = 0
        vs = set([vSt])
        while vs:
            vNexts = set()
            fuelNexts = [-1] * numV
            while vs:
                fNow, vNow = -1, -1
                for v in vs:
                    if fuels[v] > fNow:
                        fNow, vNow = fuels[v], v
                nums[vNow] = num
                useds[vNow] = True
                vs.remove(vNow)

                fuel = fuels[vNow]
                for v2, wt in adjList[vNow]:
                    if useds[v2]: continue
                    if fuel >= wt:
                        if fuel-wt > fuels[v2]:
                            fuels[v2] = fuel-wt
                        vs.add(v2)
                    elif L >= wt:
                        if L-wt > fuelNexts[v2]:
                            fuelNexts[v2] = L-wt
                        vNexts.add(v2)

            vs = set([v for v in vNexts if not useds[v]])
            fuels = fuelNexts
            num += 1
        return nums


     Dijkstra numV = len(adjList) numV len(adjList) len adjList useds = [False] * numV useds [False] * numV [False] False numV fuels = [-1] * numV fuels [-1] * numV [-1] -1 numV fuels[vSt] = L fuels[vSt] fuels vSt L nums = [INF] * numV nums [INF] * numV [INF] INF numV num = 0 num 0 vs = set([vSt]) vs set([vSt]) set [vSt] vSt while vs:
            vNexts = set()
            fuelNexts = [-1] * numV
            while vs:
                fNow, vNow = -1, -1
                for v in vs:
                    if fuels[v] > fNow:
                        fNow, vNow = fuels[v], v
                nums[vNow] = num
                useds[vNow] = True
                vs.remove(vNow)

                fuel = fuels[vNow]
                for v2, wt in adjList[vNow]:
                    if useds[v2]: continue
                    if fuel >= wt:
                        if fuel-wt > fuels[v2]:
                            fuels[v2] = fuel-wt
                        vs.add(v2)
                    elif L >= wt:
                        if L-wt > fuelNexts[v2]:
                            fuelNexts[v2] = L-wt
                        vNexts.add(v2)

            vs = set([v for v in vNexts if not useds[v]])
            fuels = fuelNexts
            num += 1
         vs vNexts = set() vNexts set() set fuelNexts = [-1] * numV fuelNexts [-1] * numV [-1] -1 numV while vs:
                fNow, vNow = -1, -1
                for v in vs:
                    if fuels[v] > fNow:
                        fNow, vNow = fuels[v], v
                nums[vNow] = num
                useds[vNow] = True
                vs.remove(vNow)

                fuel = fuels[vNow]
                for v2, wt in adjList[vNow]:
                    if useds[v2]: continue
                    if fuel >= wt:
                        if fuel-wt > fuels[v2]:
                            fuels[v2] = fuel-wt
                        vs.add(v2)
                    elif L >= wt:
                        if L-wt > fuelNexts[v2]:
                            fuelNexts[v2] = L-wt
                        vNexts.add(v2)

             vs fNow, vNow = -1, -1 fNow -1 vNow -1 for v in vs:
                    if fuels[v] > fNow:
                        fNow, vNow = fuels[v], v
                 v vs if fuels[v] > fNow:
                        fNow, vNow = fuels[v], v
                 fuels[v] > fNow fuels[v] fuels v fNow fNow, vNow = fuels[v], v fNow fuels[v] fuels v vNow v nums[vNow] = num nums[vNow] nums vNow num useds[vNow] = True useds[vNow] useds vNow True vs.remove(vNow) vs.remove vs remove vNow fuel = fuels[vNow] fuel fuels[vNow] fuels vNow for v2, wt in adjList[vNow]:
                    if useds[v2]: continue
                    if fuel >= wt:
                        if fuel-wt > fuels[v2]:
                            fuels[v2] = fuel-wt
                        vs.add(v2)
                    elif L >= wt:
                        if L-wt > fuelNexts[v2]:
                            fuelNexts[v2] = L-wt
                        vNexts.add(v2)

             v2 wt adjList[vNow] adjList vNow if useds[v2]: continue
                     useds[v2] useds v2 if fuel >= wt:
                        if fuel-wt > fuels[v2]:
                            fuels[v2] = fuel-wt
                        vs.add(v2)
                    elif L >= wt:
                        if L-wt > fuelNexts[v2]:
                            fuelNexts[v2] = L-wt
                        vNexts.add(v2)

             fuel >= wt fuel wt if fuel-wt > fuels[v2]:
                            fuels[v2] = fuel-wt
                         fuel-wt > fuels[v2] fuel-wt fuel wt fuels[v2] fuels v2 fuels[v2] = fuel-wt fuels[v2] fuels v2 fuel-wt fuel wt vs.add(v2) vs.add vs add v2 elif L >= wt:
                        if L-wt > fuelNexts[v2]:
                            fuelNexts[v2] = L-wt
                        vNexts.add(v2)

             L >= wt L wt if L-wt > fuelNexts[v2]:
                            fuelNexts[v2] = L-wt
                         L-wt > fuelNexts[v2] L-wt L wt fuelNexts[v2] fuelNexts v2 fuelNexts[v2] = L-wt fuelNexts[v2] fuelNexts v2 L-wt L wt vNexts.add(v2) vNexts.add vNexts add v2 v for v in vNexts if not useds[v] for v in vNexts if not useds[v] v vNexts not useds[v] useds[v] useds v if not useds[v] v vs = set([v for v in vNexts if not useds[v]]) vs set([v for v in vNexts if not useds[v]]) set [v for v in vNexts if not useds[v]] fuels = fuelNexts fuels fuelNexts num += 1 num 1 return nums nums adjList adjList vSt vSt 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) [] adjL = [[] for _ in range(N)] adjL [[] for _ in range(N)] for _ in range(M):
        A, B, C = map(int, input().split())
        A, B = A-1, B-1
        adjL[A].append((B, C))
        adjL[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 A, B = A-1, B-1 A A-1 A 1 B B-1 B 1 adjL[A].append((B, C)) [A].append [A] adjL A append (B, C) B C adjL[B].append((A, C)) [B].append [B] adjL B append (A, C) A C numss = [] numss [] for v in range(N):
        nums = Dijkstra(adjL, v)
        numss.append(nums)

     v range(N) range N nums = Dijkstra(adjL, v) nums Dijkstra(adjL, v) Dijkstra adjL v numss.append(nums) numss.append numss append nums Q = int(input()) Q int(input()) int input() input anss = [] anss [] for _ in range(Q):
        s, t = map(int, input().split())
        s, t = s-1, t-1
        if numss[s][t] == INF:
            anss.append(-1)
        else:
            anss.append(numss[s][t])

     _ range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t s, t = s-1, t-1 s s-1 s 1 t t-1 t 1 if numss[s][t] == INF:
            anss.append(-1)
        else:
            anss.append(numss[s][t])

     numss[s][t] == INF numss[s][t] [s] numss s t INF anss.append(-1) anss.append anss append -1 anss.append(numss[s][t]) anss.append anss append numss[s][t] [s] numss s t print('\n'.join(map(str, anss))) print '\n'.join(map(str, anss)) '\n'.join '\n' join map(str, anss) map str anss solve() solve def solve():
    INF = float('inf')

    def Dijkstra(adjList, vSt):
        numV = len(adjList)
        useds = [False] * numV
        fuels = [-1] * numV
        fuels[vSt] = L
        nums = [INF] * numV
        num = 0
        vs = set([vSt])
        while vs:
            vNexts = set()
            fuelNexts = [-1] * numV
            while vs:
                fNow, vNow = -1, -1
                for v in vs:
                    if fuels[v] > fNow:
                        fNow, vNow = fuels[v], v
                nums[vNow] = num
                useds[vNow] = True
                vs.remove(vNow)

                fuel = fuels[vNow]
                for v2, wt in adjList[vNow]:
                    if useds[v2]: continue
                    if fuel >= wt:
                        if fuel-wt > fuels[v2]:
                            fuels[v2] = fuel-wt
                        vs.add(v2)
                    elif L >= wt:
                        if L-wt > fuelNexts[v2]:
                            fuelNexts[v2] = L-wt
                        vNexts.add(v2)

            vs = set([v for v in vNexts if not useds[v]])
            fuels = fuelNexts
            num += 1
        return nums


    N, M, L = map(int, input().split())
    adjL = [[] for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        A, B = A-1, B-1
        adjL[A].append((B, C))
        adjL[B].append((A, C))

    numss = []
    for v in range(N):
        nums = Dijkstra(adjL, v)
        numss.append(nums)

    Q = int(input())
    anss = []
    for _ in range(Q):
        s, t = map(int, input().split())
        s, t = s-1, t-1
        if numss[s][t] == INF:
            anss.append(-1)
        else:
            anss.append(numss[s][t])

    print('\n'.join(map(str, anss))) def solve():
    INF = float('inf')

    def Dijkstra(adjList, vSt):
        numV = len(adjList)
        useds = [False] * numV
        fuels = [-1] * numV
        fuels[vSt] = L
        nums = [INF] * numV
        num = 0
        vs = set([vSt])
        while vs:
            vNexts = set()
            fuelNexts = [-1] * numV
            while vs:
                fNow, vNow = -1, -1
                for v in vs:
                    if fuels[v] > fNow:
                        fNow, vNow = fuels[v], v
                nums[vNow] = num
                useds[vNow] = True
                vs.remove(vNow)

                fuel = fuels[vNow]
                for v2, wt in adjList[vNow]:
                    if useds[v2]: continue
                    if fuel >= wt:
                        if fuel-wt > fuels[v2]:
                            fuels[v2] = fuel-wt
                        vs.add(v2)
                    elif L >= wt:
                        if L-wt > fuelNexts[v2]:
                            fuelNexts[v2] = L-wt
                        vNexts.add(v2)

            vs = set([v for v in vNexts if not useds[v]])
            fuels = fuelNexts
            num += 1
        return nums


    N, M, L = map(int, input().split())
    adjL = [[] for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        A, B = A-1, B-1
        adjL[A].append((B, C))
        adjL[B].append((A, C))

    numss = []
    for v in range(N):
        nums = Dijkstra(adjL, v)
        numss.append(nums)

    Q = int(input())
    anss = []
    for _ in range(Q):
        s, t = map(int, input().split())
        s, t = s-1, t-1
        if numss[s][t] == INF:
            anss.append(-1)
        else:
            anss.append(numss[s][t])

    print('\n'.join(map(str, anss))) solve
def solve():
    INF = float('inf')

    def Dijkstra(adjList, vSt):
        numV = len(adjList)
        useds = [False] * numV
        fuels = [-1] * numV
        fuels[vSt] = L
        nums = [INF] * numV
        num = 0
        vs = set([vSt])
        while vs:
            vNexts = set()
            fuelNexts = [-1] * numV
            while vs:
                fNow, vNow = -1, -1
                for v in vs:
                    if fuels[v] > fNow:
                        fNow, vNow = fuels[v], v
                nums[vNow] = num
                useds[vNow] = True
                vs.remove(vNow)

                fuel = fuels[vNow]
                for v2, wt in adjList[vNow]:
                    if useds[v2]: continue
                    if fuel >= wt:
                        if fuel-wt > fuels[v2]:
                            fuels[v2] = fuel-wt
                        vs.add(v2)
                    elif L >= wt:
                        if L-wt > fuelNexts[v2]:
                            fuelNexts[v2] = L-wt
                        vNexts.add(v2)

            vs = set([v for v in vNexts if not useds[v]])
            fuels = fuelNexts
            num += 1
        return nums


    N, M, L = map(int, input().split())
    adjL = [[] for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        A, B = A-1, B-1
        adjL[A].append((B, C))
        adjL[B].append((A, C))

    numss = []
    for v in range(N):
        nums = Dijkstra(adjL, v)
        numss.append(nums)

    Q = int(input())
    anss = []
    for _ in range(Q):
        s, t = map(int, input().split())
        s, t = s-1, t-1
        if numss[s][t] == INF:
            anss.append(-1)
        else:
            anss.append(numss[s][t])

    print('\n'.join(map(str, anss)))


solve()
