import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def wff(n,l,abc,st):
    nl = list(range(n))
    d = [[inf] * n for _ in nl]
    for i in nl:
        d[i][i] = 0
    for a,b,c in abc:
        a -= 1
        b -= 1
        d[a][b] = c
        d[b][a] = c

    for i in nl:
        di = d[i]
        for j in nl:
            if i == j:
                continue
            dj = d[j]
            for k in nl:
                if i != k and j != k and dj[k] > dj[i] + di[k]:
                    dj[k] = dj[i] + di[k]

    dd = [[inf] * n for _ in nl]
    for i in nl:
        dd[i][i] = 0
    for i in nl:
        for j in nl:
            if j != i and d[i][j] <= l:
                dd[i][j] = 1

    for i in nl:
        di = dd[i]
        for j in nl:
            if i == j:
                continue
            dj = dd[j]
            for k in nl:
                if i != k and j != k and dj[k] > dj[i] + di[k]:
                    dj[k] = dj[i] + di[k]

    rr = []
    for s,t in st:
        if dd[s][t] == inf:
            rr.append(-1)
        else:
            rr.append(dd[s][t] - 1)

    return JA(rr, "\n")


def main():
    n,m,l = LI()
    abc = [LI() for _ in range(m)]
    q = I()
    st = [LI_() for _ in range(q)]

    if m > 300 * 100:
        return wff(n,l,abc,st)

    e = collections.defaultdict(list)
    for a,b,c in abc:
        a -= 1
        b -= 1
        e[a].append((b, c))
        e[b].append((a, c))

    def search(s):
        d = collections.defaultdict(lambda: inf)
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd and vd <= l:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

        return set([k for k,v in d.items() if v <= l])

    d = {}
    for i in range(n):
        d[i] = search(i)

    dd = [[inf] * n for _ in range(n)]
    for i in range(n):
        q = [(0, i)]
        qi = 0
        v = set([i])
        while len(q) > qi:
            k, t = q[qi]
            qi += 1
            u = d[t] - v
            v |= u
            dd[i][t] = k
            for w in u:
                q.append((k+1, w))

    rr = []
    for s,t in st:
        if dd[s][t] == inf:
            rr.append(-1)
        else:
            rr.append(dd[s][t] - 1)


    return JA(rr, "\n")

print(main())


 import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools math string itertools fractions heapq collections re array bisect sys copy functools import time,random time random sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 inf = 10**20 inf 10**20 10 20 eps = 1.0 / 10**10 eps 1.0 / 10**10 1.0 10**10 10 10 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 mod2 = 998244353 mod2 998244353 dd = [(-1,0),(0,1),(1,0),(0,-1)] dd [(-1,0),(0,1),(1,0),(0,-1)] (-1,0) -1 0 (0,1) 0 1 (1,0) 1 0 (0,-1) 0 -1 ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] ddn [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] (-1,0) -1 0 (-1,1) -1 1 (0,1) 0 1 (1,1) 1 1 (1,0) 1 0 (1,-1) 1 -1 (0,-1) 0 -1 (-1,-1) -1 -1 def LI(): return list(map(int, sys.stdin.readline().split())) LI list(map(int, l.split())) for l in sys.stdin.readlines() for l in sys.stdin.readlines() l sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines for l in sys.stdin.readlines() list(map(int, l.split())) list map(int, l.split()) map int l.split() l.split l split def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] LLI int(x)-1 for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x)-1 int(x) int x 1 def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] LI_ float(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() float(x) float x def LF(): return [float(x) for x in sys.stdin.readline().split()] LF def LS(): return sys.stdin.readline().split() LS def I(): return int(sys.stdin.readline()) I def F(): return float(sys.stdin.readline()) F def S(): return input() S def pf(s): return print(s, flush=True) pf s s def pe(s): return print(str(s), file=sys.stderr) pe s s def JA(a, sep): return sep.join(map(str, a)) JA a a sep sep def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a) JAA a a s s t t def wff(n,l,abc,st):
    nl = list(range(n))
    d = [[inf] * n for _ in nl]
    for i in nl:
        d[i][i] = 0
    for a,b,c in abc:
        a -= 1
        b -= 1
        d[a][b] = c
        d[b][a] = c

    for i in nl:
        di = d[i]
        for j in nl:
            if i == j:
                continue
            dj = d[j]
            for k in nl:
                if i != k and j != k and dj[k] > dj[i] + di[k]:
                    dj[k] = dj[i] + di[k]

    dd = [[inf] * n for _ in nl]
    for i in nl:
        dd[i][i] = 0
    for i in nl:
        for j in nl:
            if j != i and d[i][j] <= l:
                dd[i][j] = 1

    for i in nl:
        di = dd[i]
        for j in nl:
            if i == j:
                continue
            dj = dd[j]
            for k in nl:
                if i != k and j != k and dj[k] > dj[i] + di[k]:
                    dj[k] = dj[i] + di[k]

    rr = []
    for s,t in st:
        if dd[s][t] == inf:
            rr.append(-1)
        else:
            rr.append(dd[s][t] - 1)

    return JA(rr, "\n") wff nl = list(range(n)) nl list(range(n)) list range(n) range n [inf] * n for _ in nl for _ in nl _ nl for _ in nl [inf] * n [inf] inf n d = [[inf] * n for _ in nl] d [[inf] * n for _ in nl] for i in nl:
        d[i][i] = 0
     i nl d[i][i] = 0 d[i][i] [i] d i i 0 for a,b,c in abc:
        a -= 1
        b -= 1
        d[a][b] = c
        d[b][a] = c

     a b c abc a -= 1 a 1 b -= 1 b 1 d[a][b] = c d[a][b] [a] d a b c d[b][a] = c d[b][a] [b] d b a c for i in nl:
        di = d[i]
        for j in nl:
            if i == j:
                continue
            dj = d[j]
            for k in nl:
                if i != k and j != k and dj[k] > dj[i] + di[k]:
                    dj[k] = dj[i] + di[k]

     i nl di = d[i] di d[i] d i for j in nl:
            if i == j:
                continue
            dj = d[j]
            for k in nl:
                if i != k and j != k and dj[k] > dj[i] + di[k]:
                    dj[k] = dj[i] + di[k]

     j nl if i == j:
                continue
             i == j i j continue dj = d[j] dj d[j] d j for k in nl:
                if i != k and j != k and dj[k] > dj[i] + di[k]:
                    dj[k] = dj[i] + di[k]

     k nl if i != k and j != k and dj[k] > dj[i] + di[k]:
                    dj[k] = dj[i] + di[k]

     i != k and j != k and dj[k] > dj[i] + di[k] i != k and j != k i != k i k j != k j k dj[k] > dj[i] + di[k] dj[k] dj k dj[i] + di[k] dj[i] dj i di[k] di k dj[k] = dj[i] + di[k] dj[k] dj k dj[i] + di[k] dj[i] dj i di[k] di k [inf] * n for _ in nl for _ in nl _ nl for _ in nl [inf] * n [inf] inf n dd = [[inf] * n for _ in nl] dd [[inf] * n for _ in nl] for i in nl:
        dd[i][i] = 0
     i nl dd[i][i] = 0 dd[i][i] [i] dd i i 0 for i in nl:
        for j in nl:
            if j != i and d[i][j] <= l:
                dd[i][j] = 1

     i nl for j in nl:
            if j != i and d[i][j] <= l:
                dd[i][j] = 1

     j nl if j != i and d[i][j] <= l:
                dd[i][j] = 1

     j != i and d[i][j] <= l j != i j i d[i][j] <= l d[i][j] [i] d i j l dd[i][j] = 1 dd[i][j] [i] dd i j 1 for i in nl:
        di = dd[i]
        for j in nl:
            if i == j:
                continue
            dj = dd[j]
            for k in nl:
                if i != k and j != k and dj[k] > dj[i] + di[k]:
                    dj[k] = dj[i] + di[k]

     i nl di = dd[i] di dd[i] dd i for j in nl:
            if i == j:
                continue
            dj = dd[j]
            for k in nl:
                if i != k and j != k and dj[k] > dj[i] + di[k]:
                    dj[k] = dj[i] + di[k]

     j nl if i == j:
                continue
             i == j i j continue dj = dd[j] dj dd[j] dd j for k in nl:
                if i != k and j != k and dj[k] > dj[i] + di[k]:
                    dj[k] = dj[i] + di[k]

     k nl if i != k and j != k and dj[k] > dj[i] + di[k]:
                    dj[k] = dj[i] + di[k]

     i != k and j != k and dj[k] > dj[i] + di[k] i != k and j != k i != k i k j != k j k dj[k] > dj[i] + di[k] dj[k] dj k dj[i] + di[k] dj[i] dj i di[k] di k dj[k] = dj[i] + di[k] dj[k] dj k dj[i] + di[k] dj[i] dj i di[k] di k rr = [] rr [] for s,t in st:
        if dd[s][t] == inf:
            rr.append(-1)
        else:
            rr.append(dd[s][t] - 1)

     s t st if dd[s][t] == inf:
            rr.append(-1)
        else:
            rr.append(dd[s][t] - 1)

     dd[s][t] == inf dd[s][t] [s] dd s t inf rr.append(-1) rr.append rr append -1 rr.append(dd[s][t] - 1) rr.append rr append dd[s][t] - 1 dd[s][t] [s] dd s t 1 return JA(rr, "\n") JA(rr, "\n") JA rr "\n" n n l l abc abc st st def main():
    n,m,l = LI()
    abc = [LI() for _ in range(m)]
    q = I()
    st = [LI_() for _ in range(q)]

    if m > 300 * 100:
        return wff(n,l,abc,st)

    e = collections.defaultdict(list)
    for a,b,c in abc:
        a -= 1
        b -= 1
        e[a].append((b, c))
        e[b].append((a, c))

    def search(s):
        d = collections.defaultdict(lambda: inf)
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd and vd <= l:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

        return set([k for k,v in d.items() if v <= l])

    d = {}
    for i in range(n):
        d[i] = search(i)

    dd = [[inf] * n for _ in range(n)]
    for i in range(n):
        q = [(0, i)]
        qi = 0
        v = set([i])
        while len(q) > qi:
            k, t = q[qi]
            qi += 1
            u = d[t] - v
            v |= u
            dd[i][t] = k
            for w in u:
                q.append((k+1, w))

    rr = []
    for s,t in st:
        if dd[s][t] == inf:
            rr.append(-1)
        else:
            rr.append(dd[s][t] - 1)


    return JA(rr, "\n") main n,m,l = LI() n LI() LI m l LI() for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) LI() LI abc = [LI() for _ in range(m)] abc [LI() for _ in range(m)] q = I() q I() I LI_() for _ in range(q) for _ in range(q) _ range(q) range q for _ in range(q) LI_() LI_ st = [LI_() for _ in range(q)] st [LI_() for _ in range(q)] if m > 300 * 100:
        return wff(n,l,abc,st)

     m > 300 * 100 m 300 * 100 300 100 return wff(n,l,abc,st) wff(n,l,abc,st) wff n l abc st e = collections.defaultdict(list) e collections.defaultdict(list) collections.defaultdict collections defaultdict list for a,b,c in abc:
        a -= 1
        b -= 1
        e[a].append((b, c))
        e[b].append((a, c))

     a b c abc 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 def search(s):
        d = collections.defaultdict(lambda: inf)
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd and vd <= l:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

        return set([k for k,v in d.items() if v <= l])

     search d = collections.defaultdict(lambda: inf) d collections.defaultdict(lambda: inf) collections.defaultdict collections defaultdict lambda: inf inf d[s] = 0 d[s] d s 0 q = [] q [] heapq.heappush(q, (0, s)) heapq.heappush heapq heappush q (0, s) 0 s v = collections.defaultdict(bool) v collections.defaultdict(bool) collections.defaultdict collections defaultdict bool while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd and vd <= l:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

         len(q) len q k, u = heapq.heappop(q) k heapq.heappop(q) heapq.heappop heapq heappop q u if v[u]:
                continue
             v[u] v u continue v[u] = True v[u] v u True for uv, ud in e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd and vd <= l:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

         uv ud e[u] e u if v[uv]:
                    continue
                 v[uv] v uv continue vd = k + ud vd k + ud k ud if d[uv] > vd and vd <= l:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

         d[uv] > vd and vd <= l d[uv] > vd d[uv] d uv vd vd <= l vd l d[uv] = vd d[uv] d uv vd heapq.heappush(q, (vd, uv)) heapq.heappush heapq heappush q (vd, uv) vd uv k for k,v in d.items() if v <= l for k,v in d.items() if v <= l k v d.items() d.items d items v <= l v l if v <= l k return set([k for k,v in d.items() if v <= l]) set([k for k,v in d.items() if v <= l]) set [k for k,v in d.items() if v <= l] s s d = {} d {} for i in range(n):
        d[i] = search(i)

     i range(n) range n d[i] = search(i) d[i] d i search(i) search i [inf] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [inf] * n [inf] inf n dd = [[inf] * n for _ in range(n)] dd [[inf] * n for _ in range(n)] for i in range(n):
        q = [(0, i)]
        qi = 0
        v = set([i])
        while len(q) > qi:
            k, t = q[qi]
            qi += 1
            u = d[t] - v
            v |= u
            dd[i][t] = k
            for w in u:
                q.append((k+1, w))

     i range(n) range n q = [(0, i)] q [(0, i)] (0, i) 0 i qi = 0 qi 0 v = set([i]) v set([i]) set [i] i while len(q) > qi:
            k, t = q[qi]
            qi += 1
            u = d[t] - v
            v |= u
            dd[i][t] = k
            for w in u:
                q.append((k+1, w))

     len(q) > qi len(q) len q qi k, t = q[qi] k q[qi] q qi t qi += 1 qi 1 u = d[t] - v u d[t] - v d[t] d t v v |= u v u dd[i][t] = k dd[i][t] [i] dd i t k for w in u:
                q.append((k+1, w))

     w u q.append((k+1, w)) q.append q append (k+1, w) k+1 k 1 w rr = [] rr [] for s,t in st:
        if dd[s][t] == inf:
            rr.append(-1)
        else:
            rr.append(dd[s][t] - 1)


     s t st if dd[s][t] == inf:
            rr.append(-1)
        else:
            rr.append(dd[s][t] - 1)


     dd[s][t] == inf dd[s][t] [s] dd s t inf rr.append(-1) rr.append rr append -1 rr.append(dd[s][t] - 1) rr.append rr append dd[s][t] - 1 dd[s][t] [s] dd s t 1 return JA(rr, "\n") JA(rr, "\n") JA rr "\n" print(main()) print main() main def LS(): return sys.stdin.readline().split() def LS(): return sys.stdin.readline().split() LS def pf(s): return print(s, flush=True) def pf(s): return print(s, flush=True) pf def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] LI_ def I(): return int(sys.stdin.readline()) def I(): return int(sys.stdin.readline()) I inf = 10**20 10**20 inf def LF(): return [float(x) for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] LF mod2 = 998244353 998244353 mod2 def pe(s): return print(str(s), file=sys.stderr) def pe(s): return print(str(s), file=sys.stderr) pe def wff(n,l,abc,st):
    nl = list(range(n))
    d = [[inf] * n for _ in nl]
    for i in nl:
        d[i][i] = 0
    for a,b,c in abc:
        a -= 1
        b -= 1
        d[a][b] = c
        d[b][a] = c

    for i in nl:
        di = d[i]
        for j in nl:
            if i == j:
                continue
            dj = d[j]
            for k in nl:
                if i != k and j != k and dj[k] > dj[i] + di[k]:
                    dj[k] = dj[i] + di[k]

    dd = [[inf] * n for _ in nl]
    for i in nl:
        dd[i][i] = 0
    for i in nl:
        for j in nl:
            if j != i and d[i][j] <= l:
                dd[i][j] = 1

    for i in nl:
        di = dd[i]
        for j in nl:
            if i == j:
                continue
            dj = dd[j]
            for k in nl:
                if i != k and j != k and dj[k] > dj[i] + di[k]:
                    dj[k] = dj[i] + di[k]

    rr = []
    for s,t in st:
        if dd[s][t] == inf:
            rr.append(-1)
        else:
            rr.append(dd[s][t] - 1)

    return JA(rr, "\n") def wff(n,l,abc,st):
    nl = list(range(n))
    d = [[inf] * n for _ in nl]
    for i in nl:
        d[i][i] = 0
    for a,b,c in abc:
        a -= 1
        b -= 1
        d[a][b] = c
        d[b][a] = c

    for i in nl:
        di = d[i]
        for j in nl:
            if i == j:
                continue
            dj = d[j]
            for k in nl:
                if i != k and j != k and dj[k] > dj[i] + di[k]:
                    dj[k] = dj[i] + di[k]

    dd = [[inf] * n for _ in nl]
    for i in nl:
        dd[i][i] = 0
    for i in nl:
        for j in nl:
            if j != i and d[i][j] <= l:
                dd[i][j] = 1

    for i in nl:
        di = dd[i]
        for j in nl:
            if i == j:
                continue
            dj = dd[j]
            for k in nl:
                if i != k and j != k and dj[k] > dj[i] + di[k]:
                    dj[k] = dj[i] + di[k]

    rr = []
    for s,t in st:
        if dd[s][t] == inf:
            rr.append(-1)
        else:
            rr.append(dd[s][t] - 1)

    return JA(rr, "\n") wff eps = 1.0 / 10**10 1.0 / 10**10 eps ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] ddn def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a) def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a) JAA def LI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) LI def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] LLI def main():
    n,m,l = LI()
    abc = [LI() for _ in range(m)]
    q = I()
    st = [LI_() for _ in range(q)]

    if m > 300 * 100:
        return wff(n,l,abc,st)

    e = collections.defaultdict(list)
    for a,b,c in abc:
        a -= 1
        b -= 1
        e[a].append((b, c))
        e[b].append((a, c))

    def search(s):
        d = collections.defaultdict(lambda: inf)
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd and vd <= l:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

        return set([k for k,v in d.items() if v <= l])

    d = {}
    for i in range(n):
        d[i] = search(i)

    dd = [[inf] * n for _ in range(n)]
    for i in range(n):
        q = [(0, i)]
        qi = 0
        v = set([i])
        while len(q) > qi:
            k, t = q[qi]
            qi += 1
            u = d[t] - v
            v |= u
            dd[i][t] = k
            for w in u:
                q.append((k+1, w))

    rr = []
    for s,t in st:
        if dd[s][t] == inf:
            rr.append(-1)
        else:
            rr.append(dd[s][t] - 1)


    return JA(rr, "\n") def main():
    n,m,l = LI()
    abc = [LI() for _ in range(m)]
    q = I()
    st = [LI_() for _ in range(q)]

    if m > 300 * 100:
        return wff(n,l,abc,st)

    e = collections.defaultdict(list)
    for a,b,c in abc:
        a -= 1
        b -= 1
        e[a].append((b, c))
        e[b].append((a, c))

    def search(s):
        d = collections.defaultdict(lambda: inf)
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd and vd <= l:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

        return set([k for k,v in d.items() if v <= l])

    d = {}
    for i in range(n):
        d[i] = search(i)

    dd = [[inf] * n for _ in range(n)]
    for i in range(n):
        q = [(0, i)]
        qi = 0
        v = set([i])
        while len(q) > qi:
            k, t = q[qi]
            qi += 1
            u = d[t] - v
            v |= u
            dd[i][t] = k
            for w in u:
                q.append((k+1, w))

    rr = []
    for s,t in st:
        if dd[s][t] == inf:
            rr.append(-1)
        else:
            rr.append(dd[s][t] - 1)


    return JA(rr, "\n") main dd = [(-1,0),(0,1),(1,0),(0,-1)] [(-1,0),(0,1),(1,0),(0,-1)] dd def S(): return input() def S(): return input() S def JA(a, sep): return sep.join(map(str, a)) def JA(a, sep): return sep.join(map(str, a)) JA def F(): return float(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) F mod = 10**9+7 10**9+7 mod
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def wff(n,l,abc,st):
    nl = list(range(n))
    d = [[inf] * n for _ in nl]
    for i in nl:
        d[i][i] = 0
    for a,b,c in abc:
        a -= 1
        b -= 1
        d[a][b] = c
        d[b][a] = c

    for i in nl:
        di = d[i]
        for j in nl:
            if i == j:
                continue
            dj = d[j]
            for k in nl:
                if i != k and j != k and dj[k] > dj[i] + di[k]:
                    dj[k] = dj[i] + di[k]

    dd = [[inf] * n for _ in nl]
    for i in nl:
        dd[i][i] = 0
    for i in nl:
        for j in nl:
            if j != i and d[i][j] <= l:
                dd[i][j] = 1

    for i in nl:
        di = dd[i]
        for j in nl:
            if i == j:
                continue
            dj = dd[j]
            for k in nl:
                if i != k and j != k and dj[k] > dj[i] + di[k]:
                    dj[k] = dj[i] + di[k]

    rr = []
    for s,t in st:
        if dd[s][t] == inf:
            rr.append(-1)
        else:
            rr.append(dd[s][t] - 1)

    return JA(rr, "\n")


def main():
    n,m,l = LI()
    abc = [LI() for _ in range(m)]
    q = I()
    st = [LI_() for _ in range(q)]

    if m > 300 * 100:
        return wff(n,l,abc,st)

    e = collections.defaultdict(list)
    for a,b,c in abc:
        a -= 1
        b -= 1
        e[a].append((b, c))
        e[b].append((a, c))

    def search(s):
        d = collections.defaultdict(lambda: inf)
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd and vd <= l:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

        return set([k for k,v in d.items() if v <= l])

    d = {}
    for i in range(n):
        d[i] = search(i)

    dd = [[inf] * n for _ in range(n)]
    for i in range(n):
        q = [(0, i)]
        qi = 0
        v = set([i])
        while len(q) > qi:
            k, t = q[qi]
            qi += 1
            u = d[t] - v
            v |= u
            dd[i][t] = k
            for w in u:
                q.append((k+1, w))

    rr = []
    for s,t in st:
        if dd[s][t] == inf:
            rr.append(-1)
        else:
            rr.append(dd[s][t] - 1)


    return JA(rr, "\n")

print(main())



