import sys


def naive_dijkstra(links, n, l):
    F30 = (1 << 30) - 1
    INF = 10 ** 18

    refuels = [[-1] * n for _ in range(n)]

    for s in range(n):
        rs = refuels[s]

        dists = [INF] * n
        dists[s] = 0
        remain_nodes = set(range(n))

        for _ in range(n):
            v = -1
            w = INF
            for u in remain_nodes:
                if dists[u] < w:
                    v = u
                    w = dists[u]
            if v == -1:
                break
            remain_nodes.remove(v)

            count = w >> 30
            used = w & F30
            rs[v] = count

            for u, c in links[v]:
                if l - used < c:
                    nw = ((count + 1) << 30) | c
                else:
                    nw = w + c
                if nw < dists[u]:
                    dists[u] = nw

    return refuels


n, m, l = list(map(int, input().split()))
lines = sys.stdin.readlines()

links = [set() for _ in range(n)]

for line in lines[:m]:
    a, b, c = map(int, line.split())
    a -= 1
    b -= 1
    if l < c:
        continue
    links[a].add((b, c))
    links[b].add((a, c))

dists = naive_dijkstra(links, n, l)
buf = []

for line in lines[m + 1:]:
    s, t = map(int, line.split())
    buf.append(dists[s - 1][t - 1])

print('\n'.join(map(str, buf))) import sys sys def naive_dijkstra(links, n, l):
    F30 = (1 << 30) - 1
    INF = 10 ** 18

    refuels = [[-1] * n for _ in range(n)]

    for s in range(n):
        rs = refuels[s]

        dists = [INF] * n
        dists[s] = 0
        remain_nodes = set(range(n))

        for _ in range(n):
            v = -1
            w = INF
            for u in remain_nodes:
                if dists[u] < w:
                    v = u
                    w = dists[u]
            if v == -1:
                break
            remain_nodes.remove(v)

            count = w >> 30
            used = w & F30
            rs[v] = count

            for u, c in links[v]:
                if l - used < c:
                    nw = ((count + 1) << 30) | c
                else:
                    nw = w + c
                if nw < dists[u]:
                    dists[u] = nw

    return refuels naive_dijkstra F30 = (1 << 30) - 1 F30 (1 << 30) - 1 1 << 30 1 30 1 INF = 10 ** 18 INF 10 ** 18 10 18 [-1] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [-1] * n [-1] -1 n refuels = [[-1] * n for _ in range(n)] refuels [[-1] * n for _ in range(n)] for s in range(n):
        rs = refuels[s]

        dists = [INF] * n
        dists[s] = 0
        remain_nodes = set(range(n))

        for _ in range(n):
            v = -1
            w = INF
            for u in remain_nodes:
                if dists[u] < w:
                    v = u
                    w = dists[u]
            if v == -1:
                break
            remain_nodes.remove(v)

            count = w >> 30
            used = w & F30
            rs[v] = count

            for u, c in links[v]:
                if l - used < c:
                    nw = ((count + 1) << 30) | c
                else:
                    nw = w + c
                if nw < dists[u]:
                    dists[u] = nw

     s range(n) range n rs = refuels[s] rs refuels[s] refuels s dists = [INF] * n dists [INF] * n [INF] INF n dists[s] = 0 dists[s] dists s 0 remain_nodes = set(range(n)) remain_nodes set(range(n)) set range(n) range n for _ in range(n):
            v = -1
            w = INF
            for u in remain_nodes:
                if dists[u] < w:
                    v = u
                    w = dists[u]
            if v == -1:
                break
            remain_nodes.remove(v)

            count = w >> 30
            used = w & F30
            rs[v] = count

            for u, c in links[v]:
                if l - used < c:
                    nw = ((count + 1) << 30) | c
                else:
                    nw = w + c
                if nw < dists[u]:
                    dists[u] = nw

     _ range(n) range n v = -1 v -1 w = INF w INF for u in remain_nodes:
                if dists[u] < w:
                    v = u
                    w = dists[u]
             u remain_nodes if dists[u] < w:
                    v = u
                    w = dists[u]
             dists[u] < w dists[u] dists u w v = u v u w = dists[u] w dists[u] dists u if v == -1:
                break
             v == -1 v -1 break remain_nodes.remove(v) remain_nodes.remove remain_nodes remove v count = w >> 30 count w >> 30 w 30 used = w & F30 used w & F30 w F30 rs[v] = count rs[v] rs v count for u, c in links[v]:
                if l - used < c:
                    nw = ((count + 1) << 30) | c
                else:
                    nw = w + c
                if nw < dists[u]:
                    dists[u] = nw

     u c links[v] links v if l - used < c:
                    nw = ((count + 1) << 30) | c
                else:
                    nw = w + c
                 l - used < c l - used l used c nw = ((count + 1) << 30) | c nw ((count + 1) << 30) | c (count + 1) << 30 count + 1 count 1 30 c nw = w + c nw w + c w c if nw < dists[u]:
                    dists[u] = nw

     nw < dists[u] nw dists[u] dists u dists[u] = nw dists[u] dists u nw return refuels refuels links links n n l l n, m, l = list(map(int, input().split())) n list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split m l lines = sys.stdin.readlines() lines sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines set() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) set() set links = [set() for _ in range(n)] links [set() for _ in range(n)] for line in lines[:m]:
    a, b, c = map(int, line.split())
    a -= 1
    b -= 1
    if l < c:
        continue
    links[a].add((b, c))
    links[b].add((a, c)) line lines[:m] lines :m m a, b, c = map(int, line.split()) a map(int, line.split()) map int line.split() line.split line split b c a -= 1 a 1 b -= 1 b 1 if l < c:
        continue
     l < c l c continue links[a].add((b, c)) [a].add [a] links a add (b, c) b c links[b].add((a, c)) [b].add [b] links b add (a, c) a c dists = naive_dijkstra(links, n, l) dists naive_dijkstra(links, n, l) naive_dijkstra links n l buf = [] buf [] for line in lines[m + 1:]:
    s, t = map(int, line.split())
    buf.append(dists[s - 1][t - 1]) line lines[m + 1:] lines m + 1: m + 1 m 1 s, t = map(int, line.split()) s map(int, line.split()) map int line.split() line.split line split t buf.append(dists[s - 1][t - 1]) buf.append buf append dists[s - 1][t - 1] [s - 1] dists s - 1 s 1 t - 1 t 1 print('\n'.join(map(str, buf))) print '\n'.join(map(str, buf)) '\n'.join '\n' join map(str, buf) map str buf a -= 1 1 a l = list(map(int, input().split())) list(map(int, input().split())) l links = [set() for _ in range(n)] [set() for _ in range(n)] links buf = [] [] buf s, t = map(int, line.split()) map(int, line.split()) s t = map(int, line.split()) map(int, line.split()) t b, c = map(int, line.split()) map(int, line.split()) b c = map(int, line.split()) map(int, line.split()) c lines = sys.stdin.readlines() sys.stdin.readlines() lines dists = naive_dijkstra(links, n, l) naive_dijkstra(links, n, l) dists n, m, l = list(map(int, input().split())) list(map(int, input().split())) n def naive_dijkstra(links, n, l):
    F30 = (1 << 30) - 1
    INF = 10 ** 18

    refuels = [[-1] * n for _ in range(n)]

    for s in range(n):
        rs = refuels[s]

        dists = [INF] * n
        dists[s] = 0
        remain_nodes = set(range(n))

        for _ in range(n):
            v = -1
            w = INF
            for u in remain_nodes:
                if dists[u] < w:
                    v = u
                    w = dists[u]
            if v == -1:
                break
            remain_nodes.remove(v)

            count = w >> 30
            used = w & F30
            rs[v] = count

            for u, c in links[v]:
                if l - used < c:
                    nw = ((count + 1) << 30) | c
                else:
                    nw = w + c
                if nw < dists[u]:
                    dists[u] = nw

    return refuels def naive_dijkstra(links, n, l):
    F30 = (1 << 30) - 1
    INF = 10 ** 18

    refuels = [[-1] * n for _ in range(n)]

    for s in range(n):
        rs = refuels[s]

        dists = [INF] * n
        dists[s] = 0
        remain_nodes = set(range(n))

        for _ in range(n):
            v = -1
            w = INF
            for u in remain_nodes:
                if dists[u] < w:
                    v = u
                    w = dists[u]
            if v == -1:
                break
            remain_nodes.remove(v)

            count = w >> 30
            used = w & F30
            rs[v] = count

            for u, c in links[v]:
                if l - used < c:
                    nw = ((count + 1) << 30) | c
                else:
                    nw = w + c
                if nw < dists[u]:
                    dists[u] = nw

    return refuels naive_dijkstra b -= 1 1 b a, b, c = map(int, line.split()) map(int, line.split()) a m, l = list(map(int, input().split())) list(map(int, input().split())) m
import sys


def naive_dijkstra(links, n, l):
    F30 = (1 << 30) - 1
    INF = 10 ** 18

    refuels = [[-1] * n for _ in range(n)]

    for s in range(n):
        rs = refuels[s]

        dists = [INF] * n
        dists[s] = 0
        remain_nodes = set(range(n))

        for _ in range(n):
            v = -1
            w = INF
            for u in remain_nodes:
                if dists[u] < w:
                    v = u
                    w = dists[u]
            if v == -1:
                break
            remain_nodes.remove(v)

            count = w >> 30
            used = w & F30
            rs[v] = count

            for u, c in links[v]:
                if l - used < c:
                    nw = ((count + 1) << 30) | c
                else:
                    nw = w + c
                if nw < dists[u]:
                    dists[u] = nw

    return refuels


n, m, l = list(map(int, input().split()))
lines = sys.stdin.readlines()

links = [set() for _ in range(n)]

for line in lines[:m]:
    a, b, c = map(int, line.split())
    a -= 1
    b -= 1
    if l < c:
        continue
    links[a].add((b, c))
    links[b].add((a, c))

dists = naive_dijkstra(links, n, l)
buf = []

for line in lines[m + 1:]:
    s, t = map(int, line.split())
    buf.append(dists[s - 1][t - 1])

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