# scipy使う場合
import sys
input = sys.stdin.readline
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

n,m,l = map(int,input().split())

# m行の入力から距離を値に持つ隣接行列を作成 0-indexed
# directed:無向グラフならFalse、有向グラフならTrue
def make_d_matrix(n,m,directed=False):
    inf = 10**13
    d = [[inf] * n for _ in range(n)]
    if(directed):
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
    else:
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
            d[b-1][a-1] = c
    return d

d = make_d_matrix(n,m)
csr_graph = csr_matrix(d)
d1 = floyd_warshall(csr_graph,directed=False)

inf = 10**3
for i in range(n):
    for j in range(n):
        d1[i][j] = 1 if (d1[i][j] <= l) else inf

csr_graph = csr_matrix(d1)
d2 = floyd_warshall(csr_graph,directed=False)

q = int(input())

for _ in range(q):
    s,t = map(int, input().split())
    tmp = d2[s-1][t-1]
    if(tmp >= inf):
        print(-1)
    else:
        print(int(tmp-1)) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix n,m,l = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l def make_d_matrix(n,m,directed=False):
    inf = 10**13
    d = [[inf] * n for _ in range(n)]
    if(directed):
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
    else:
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
            d[b-1][a-1] = c
    return d make_d_matrix inf = 10**13 inf 10**13 10 13 [inf] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [inf] * n [inf] inf n d = [[inf] * n for _ in range(n)] d [[inf] * n for _ in range(n)] if(directed):
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
    else:
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
            d[b-1][a-1] = c
     directed for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = 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 d[a-1][b-1] = c d[a-1][b-1] [a-1] d a-1 a 1 b-1 b 1 c for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
            d[b-1][a-1] = 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 d[a-1][b-1] = c d[a-1][b-1] [a-1] d a-1 a 1 b-1 b 1 c d[b-1][a-1] = c d[b-1][a-1] [b-1] d b-1 b 1 a-1 a 1 c return d d n n m m directed=False directed False d = make_d_matrix(n,m) d make_d_matrix(n,m) make_d_matrix n m csr_graph = csr_matrix(d) csr_graph csr_matrix(d) csr_matrix d d1 = floyd_warshall(csr_graph,directed=False) d1 floyd_warshall(csr_graph,directed=False) floyd_warshall csr_graph directed=False directed False inf = 10**3 inf 10**3 10 3 for i in range(n):
    for j in range(n):
        d1[i][j] = 1 if (d1[i][j] <= l) else inf i range(n) range n for j in range(n):
        d1[i][j] = 1 if (d1[i][j] <= l) else inf j range(n) range n d1[i][j] = 1 if (d1[i][j] <= l) else inf d1[i][j] [i] d1 i j 1 if (d1[i][j] <= l) else inf d1[i][j] <= l d1[i][j] [i] d1 i j l 1 inf csr_graph = csr_matrix(d1) csr_graph csr_matrix(d1) csr_matrix d1 d2 = floyd_warshall(csr_graph,directed=False) d2 floyd_warshall(csr_graph,directed=False) floyd_warshall csr_graph directed=False directed False q = int(input()) q int(input()) int input() input for _ in range(q):
    s,t = map(int, input().split())
    tmp = d2[s-1][t-1]
    if(tmp >= inf):
        print(-1)
    else:
        print(int(tmp-1)) _ range(q) range q s,t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t tmp = d2[s-1][t-1] tmp d2[s-1][t-1] [s-1] d2 s-1 s 1 t-1 t 1 if(tmp >= inf):
        print(-1)
    else:
        print(int(tmp-1)) tmp >= inf tmp inf print(-1) print -1 print(int(tmp-1)) print int(tmp-1) int tmp-1 tmp 1 n,m,l = map(int,input().split()) map(int,input().split()) n q = int(input()) int(input()) q csr_graph = csr_matrix(d1) csr_matrix(d1) csr_graph l = map(int,input().split()) map(int,input().split()) l t = map(int, input().split()) map(int, input().split()) t csr_graph = csr_matrix(d) csr_matrix(d) csr_graph d2 = floyd_warshall(csr_graph,directed=False) floyd_warshall(csr_graph,directed=False) d2 s,t = map(int, input().split()) map(int, input().split()) s m,l = map(int,input().split()) map(int,input().split()) m inf = 10**3 10**3 inf d = make_d_matrix(n,m) make_d_matrix(n,m) d d1 = floyd_warshall(csr_graph,directed=False) floyd_warshall(csr_graph,directed=False) d1 def make_d_matrix(n,m,directed=False):
    inf = 10**13
    d = [[inf] * n for _ in range(n)]
    if(directed):
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
    else:
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
            d[b-1][a-1] = c
    return d def make_d_matrix(n,m,directed=False):
    inf = 10**13
    d = [[inf] * n for _ in range(n)]
    if(directed):
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
    else:
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
            d[b-1][a-1] = c
    return d make_d_matrix input = sys.stdin.readline sys.stdin.readline input tmp = d2[s-1][t-1] d2[s-1][t-1] tmp
# scipy使う場合
import sys
input = sys.stdin.readline
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

n,m,l = map(int,input().split())

# m行の入力から距離を値に持つ隣接行列を作成 0-indexed
# directed:無向グラフならFalse、有向グラフならTrue
def make_d_matrix(n,m,directed=False):
    inf = 10**13
    d = [[inf] * n for _ in range(n)]
    if(directed):
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
    else:
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
            d[b-1][a-1] = c
    return d

d = make_d_matrix(n,m)
csr_graph = csr_matrix(d)
d1 = floyd_warshall(csr_graph,directed=False)

inf = 10**3
for i in range(n):
    for j in range(n):
        d1[i][j] = 1 if (d1[i][j] <= l) else inf

csr_graph = csr_matrix(d1)
d2 = floyd_warshall(csr_graph,directed=False)

q = int(input())

for _ in range(q):
    s,t = map(int, input().split())
    tmp = d2[s-1][t-1]
    if(tmp >= inf):
        print(-1)
    else:
        print(int(tmp-1))
