#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    n, m, l = LI()
    dist = [[inf] * n for i in range(n)]

    for _ in range(m):
        a, b, c = LI_()
        c += 1
        if c > l:
            continue
        dist[a][b] = c
        dist[b][a] = c

    supply = [[n] * n for i in range(n)]
    for k in range(n):
        distk = dist[k]
        for i in range(n):
            if i == k:
                continue
            disti = dist[i]
            distik = dist[i][k]
            for j in range(i + 1, n):
                if distik + distk[j] < disti[j]:
                    disti[j] = distik + distk[j]
                    dist[j][i] = disti[j]

    lis = [[] for i in range(n)]
    for i in range(n):
        for j in range(i + 1, n):
            if dist[i][j] <= l:
                supply[i][j] = 0
                supply[j][i] = 0
                lis[i].append(j)
                lis[j].append(i)

    for i in range(n):
        q = []
        for k in lis[i]:
            heappush(q, (0, k))
        supplyi = supply[i]

        while q:
            time, p = heappop(q)
            for k in lis[p]:
                if supplyi[k] > time + 1:
                    supplyi[k] = time + 1
                    heappush(q, (time + 1, k))

    q = II()
    for _ in range(q):
        s, t = LI_()
        if dist[s][t] == inf:
            print(-1)
            continue
        else:
            print(supply[s][t])
    return


#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    E() from collections import defaultdict,deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys random itertools math sys.setrecursionlimit(10**5) sys.setrecursionlimit sys setrecursionlimit 10**5 10 5 input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sqrt = math.sqrt sqrt math.sqrt math sqrt def LI(): return list(map(int, input().split())) LI def LF(): return list(map(float, input().split())) LF def LI_(): return list(map(lambda x: int(x)-1, input().split())) LI_ def II(): return int(input()) II def IF(): return float(input()) IF def LS(): return list(map(list, input().split())) LS def S(): return list(input().rstrip()) S II() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) II() II def IR(n): return [II() for _ in range(n)] IR n n LI() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LI() LI def LIR(n): return [LI() for _ in range(n)] LIR n n IF() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) IF() IF def FR(n): return [IF() for _ in range(n)] FR n n LI() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LI() LI def LFR(n): return [LI() for _ in range(n)] LFR n n LI_() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LI_() LI_ def LIR_(n): return [LI_() for _ in range(n)] LIR_ n n S() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) S() S def SR(n): return [S() for _ in range(n)] SR n n LS() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LS() LS def LSR(n): return [LS() for _ in range(n)] LSR n n mod = 1000000007 mod 1000000007 inf = float('INF') inf float('INF') float 'INF' def A():
    return

#B A return def B():
    return

#C B return def C():
    return

#D C return def D():
    return

#E D return def E():
    n, m, l = LI()
    dist = [[inf] * n for i in range(n)]

    for _ in range(m):
        a, b, c = LI_()
        c += 1
        if c > l:
            continue
        dist[a][b] = c
        dist[b][a] = c

    supply = [[n] * n for i in range(n)]
    for k in range(n):
        distk = dist[k]
        for i in range(n):
            if i == k:
                continue
            disti = dist[i]
            distik = dist[i][k]
            for j in range(i + 1, n):
                if distik + distk[j] < disti[j]:
                    disti[j] = distik + distk[j]
                    dist[j][i] = disti[j]

    lis = [[] for i in range(n)]
    for i in range(n):
        for j in range(i + 1, n):
            if dist[i][j] <= l:
                supply[i][j] = 0
                supply[j][i] = 0
                lis[i].append(j)
                lis[j].append(i)

    for i in range(n):
        q = []
        for k in lis[i]:
            heappush(q, (0, k))
        supplyi = supply[i]

        while q:
            time, p = heappop(q)
            for k in lis[p]:
                if supplyi[k] > time + 1:
                    supplyi[k] = time + 1
                    heappush(q, (time + 1, k))

    q = II()
    for _ in range(q):
        s, t = LI_()
        if dist[s][t] == inf:
            print(-1)
            continue
        else:
            print(supply[s][t])
    return


#F E n, m, l = LI() n LI() LI m l [inf] * n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [inf] * n [inf] inf n dist = [[inf] * n for i in range(n)] dist [[inf] * n for i in range(n)] for _ in range(m):
        a, b, c = LI_()
        c += 1
        if c > l:
            continue
        dist[a][b] = c
        dist[b][a] = c

     _ range(m) range m a, b, c = LI_() a LI_() LI_ b c c += 1 c 1 if c > l:
            continue
         c > l c l continue dist[a][b] = c dist[a][b] [a] dist a b c dist[b][a] = c dist[b][a] [b] dist b a c [n] * n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [n] * n [n] n n supply = [[n] * n for i in range(n)] supply [[n] * n for i in range(n)] for k in range(n):
        distk = dist[k]
        for i in range(n):
            if i == k:
                continue
            disti = dist[i]
            distik = dist[i][k]
            for j in range(i + 1, n):
                if distik + distk[j] < disti[j]:
                    disti[j] = distik + distk[j]
                    dist[j][i] = disti[j]

     k range(n) range n distk = dist[k] distk dist[k] dist k for i in range(n):
            if i == k:
                continue
            disti = dist[i]
            distik = dist[i][k]
            for j in range(i + 1, n):
                if distik + distk[j] < disti[j]:
                    disti[j] = distik + distk[j]
                    dist[j][i] = disti[j]

     i range(n) range n if i == k:
                continue
             i == k i k continue disti = dist[i] disti dist[i] dist i distik = dist[i][k] distik dist[i][k] [i] dist i k for j in range(i + 1, n):
                if distik + distk[j] < disti[j]:
                    disti[j] = distik + distk[j]
                    dist[j][i] = disti[j]

     j range(i + 1, n) range i + 1 i 1 n if distik + distk[j] < disti[j]:
                    disti[j] = distik + distk[j]
                    dist[j][i] = disti[j]

     distik + distk[j] < disti[j] distik + distk[j] distik distk[j] distk j disti[j] disti j disti[j] = distik + distk[j] disti[j] disti j distik + distk[j] distik distk[j] distk j dist[j][i] = disti[j] dist[j][i] [j] dist j i disti[j] disti j [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] lis = [[] for i in range(n)] lis [[] for i in range(n)] for i in range(n):
        for j in range(i + 1, n):
            if dist[i][j] <= l:
                supply[i][j] = 0
                supply[j][i] = 0
                lis[i].append(j)
                lis[j].append(i)

     i range(n) range n for j in range(i + 1, n):
            if dist[i][j] <= l:
                supply[i][j] = 0
                supply[j][i] = 0
                lis[i].append(j)
                lis[j].append(i)

     j range(i + 1, n) range i + 1 i 1 n if dist[i][j] <= l:
                supply[i][j] = 0
                supply[j][i] = 0
                lis[i].append(j)
                lis[j].append(i)

     dist[i][j] <= l dist[i][j] [i] dist i j l supply[i][j] = 0 supply[i][j] [i] supply i j 0 supply[j][i] = 0 supply[j][i] [j] supply j i 0 lis[i].append(j) [i].append [i] lis i append j lis[j].append(i) [j].append [j] lis j append i for i in range(n):
        q = []
        for k in lis[i]:
            heappush(q, (0, k))
        supplyi = supply[i]

        while q:
            time, p = heappop(q)
            for k in lis[p]:
                if supplyi[k] > time + 1:
                    supplyi[k] = time + 1
                    heappush(q, (time + 1, k))

     i range(n) range n q = [] q [] for k in lis[i]:
            heappush(q, (0, k))
         k lis[i] lis i heappush(q, (0, k)) heappush q (0, k) 0 k supplyi = supply[i] supplyi supply[i] supply i while q:
            time, p = heappop(q)
            for k in lis[p]:
                if supplyi[k] > time + 1:
                    supplyi[k] = time + 1
                    heappush(q, (time + 1, k))

     q time, p = heappop(q) time heappop(q) heappop q p for k in lis[p]:
                if supplyi[k] > time + 1:
                    supplyi[k] = time + 1
                    heappush(q, (time + 1, k))

     k lis[p] lis p if supplyi[k] > time + 1:
                    supplyi[k] = time + 1
                    heappush(q, (time + 1, k))

     supplyi[k] > time + 1 supplyi[k] supplyi k time + 1 time 1 supplyi[k] = time + 1 supplyi[k] supplyi k time + 1 time 1 heappush(q, (time + 1, k)) heappush q (time + 1, k) time + 1 time 1 k q = II() q II() II for _ in range(q):
        s, t = LI_()
        if dist[s][t] == inf:
            print(-1)
            continue
        else:
            print(supply[s][t])
     _ range(q) range q s, t = LI_() s LI_() LI_ t if dist[s][t] == inf:
            print(-1)
            continue
        else:
            print(supply[s][t])
     dist[s][t] == inf dist[s][t] [s] dist s t inf print(-1) print -1 continue print(supply[s][t]) print supply[s][t] [s] supply s t return def F():
    return

#G F return def G():
    return

#H G return def H():
    return

#Solve H return if __name__ == '__main__':
    E() __name__ == '__main__' __name__ '__main__' E() E def B():
    return

#C def B():
    return

#C B def H():
    return

#Solve def H():
    return

#Solve H def E():
    n, m, l = LI()
    dist = [[inf] * n for i in range(n)]

    for _ in range(m):
        a, b, c = LI_()
        c += 1
        if c > l:
            continue
        dist[a][b] = c
        dist[b][a] = c

    supply = [[n] * n for i in range(n)]
    for k in range(n):
        distk = dist[k]
        for i in range(n):
            if i == k:
                continue
            disti = dist[i]
            distik = dist[i][k]
            for j in range(i + 1, n):
                if distik + distk[j] < disti[j]:
                    disti[j] = distik + distk[j]
                    dist[j][i] = disti[j]

    lis = [[] for i in range(n)]
    for i in range(n):
        for j in range(i + 1, n):
            if dist[i][j] <= l:
                supply[i][j] = 0
                supply[j][i] = 0
                lis[i].append(j)
                lis[j].append(i)

    for i in range(n):
        q = []
        for k in lis[i]:
            heappush(q, (0, k))
        supplyi = supply[i]

        while q:
            time, p = heappop(q)
            for k in lis[p]:
                if supplyi[k] > time + 1:
                    supplyi[k] = time + 1
                    heappush(q, (time + 1, k))

    q = II()
    for _ in range(q):
        s, t = LI_()
        if dist[s][t] == inf:
            print(-1)
            continue
        else:
            print(supply[s][t])
    return


#F def E():
    n, m, l = LI()
    dist = [[inf] * n for i in range(n)]

    for _ in range(m):
        a, b, c = LI_()
        c += 1
        if c > l:
            continue
        dist[a][b] = c
        dist[b][a] = c

    supply = [[n] * n for i in range(n)]
    for k in range(n):
        distk = dist[k]
        for i in range(n):
            if i == k:
                continue
            disti = dist[i]
            distik = dist[i][k]
            for j in range(i + 1, n):
                if distik + distk[j] < disti[j]:
                    disti[j] = distik + distk[j]
                    dist[j][i] = disti[j]

    lis = [[] for i in range(n)]
    for i in range(n):
        for j in range(i + 1, n):
            if dist[i][j] <= l:
                supply[i][j] = 0
                supply[j][i] = 0
                lis[i].append(j)
                lis[j].append(i)

    for i in range(n):
        q = []
        for k in lis[i]:
            heappush(q, (0, k))
        supplyi = supply[i]

        while q:
            time, p = heappop(q)
            for k in lis[p]:
                if supplyi[k] > time + 1:
                    supplyi[k] = time + 1
                    heappush(q, (time + 1, k))

    q = II()
    for _ in range(q):
        s, t = LI_()
        if dist[s][t] == inf:
            print(-1)
            continue
        else:
            print(supply[s][t])
    return


#F E def IF(): return float(input()) def IF(): return float(input()) IF mod = 1000000007 1000000007 mod def LSR(n): return [LS() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] LSR def A():
    return

#B def A():
    return

#B A sqrt = math.sqrt math.sqrt sqrt def SR(n): return [S() for _ in range(n)] def SR(n): return [S() for _ in range(n)] SR def LF(): return list(map(float, input().split())) def LF(): return list(map(float, input().split())) LF def II(): return int(input()) def II(): return int(input()) II def G():
    return

#H def G():
    return

#H G def LFR(n): return [LI() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] LFR inf = float('INF') float('INF') inf input = sys.stdin.readline sys.stdin.readline input def C():
    return

#D def C():
    return

#D C def F():
    return

#G def F():
    return

#G F def LIR(n): return [LI() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] LIR def LIR_(n): return [LI_() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] LIR_ def LI_(): return list(map(lambda x: int(x)-1, input().split())) def LI_(): return list(map(lambda x: int(x)-1, input().split())) LI_ def LS(): return list(map(list, input().split())) def LS(): return list(map(list, input().split())) LS def FR(n): return [IF() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] FR def S(): return list(input().rstrip()) def S(): return list(input().rstrip()) S def LI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) LI def IR(n): return [II() for _ in range(n)] def IR(n): return [II() for _ in range(n)] IR def D():
    return

#E def D():
    return

#E D
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    n, m, l = LI()
    dist = [[inf] * n for i in range(n)]

    for _ in range(m):
        a, b, c = LI_()
        c += 1
        if c > l:
            continue
        dist[a][b] = c
        dist[b][a] = c

    supply = [[n] * n for i in range(n)]
    for k in range(n):
        distk = dist[k]
        for i in range(n):
            if i == k:
                continue
            disti = dist[i]
            distik = dist[i][k]
            for j in range(i + 1, n):
                if distik + distk[j] < disti[j]:
                    disti[j] = distik + distk[j]
                    dist[j][i] = disti[j]

    lis = [[] for i in range(n)]
    for i in range(n):
        for j in range(i + 1, n):
            if dist[i][j] <= l:
                supply[i][j] = 0
                supply[j][i] = 0
                lis[i].append(j)
                lis[j].append(i)

    for i in range(n):
        q = []
        for k in lis[i]:
            heappush(q, (0, k))
        supplyi = supply[i]

        while q:
            time, p = heappop(q)
            for k in lis[p]:
                if supplyi[k] > time + 1:
                    supplyi[k] = time + 1
                    heappush(q, (time + 1, k))

    q = II()
    for _ in range(q):
        s, t = LI_()
        if dist[s][t] == inf:
            print(-1)
            continue
        else:
            print(supply[s][t])
    return


#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    E()
