def warshall_floyd(G):
    inf = 10**18
    # 重みつきグラフGに対してすべての頂点対の距離を求める
    n = len(G)
    d = [[inf for i in range(n)] for j in range(n)]
    for i in range(n):
        d[i][i] = 0
        for j in G[i].keys():
            d[i][j] = G[i][j]
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
    return d


n, m, l = map(int, input().split())
G = [{} for i in range(n)]
for j in range(m):
    a, b, c = map(int, input().split())
    G[a-1][b-1] = c
    G[b-1][a-1] = c
D = warshall_floyd(G)
G = [{} for i in range(n)]
for i in range(n):
    for j in range(n):
        if D[i][j] <= l:
            G[i][j] = 1
D = warshall_floyd(G)
for k in range(int(input())):
    s, t = map(int, input().split())
    if D[s-1][t-1] > 10**10:
        print(-1)
    else:
        print(D[s-1][t-1]-1) def warshall_floyd(G):
    inf = 10**18
    # 重みつきグラフGに対してすべての頂点対の距離を求める
    n = len(G)
    d = [[inf for i in range(n)] for j in range(n)]
    for i in range(n):
        d[i][i] = 0
        for j in G[i].keys():
            d[i][j] = G[i][j]
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
    return d warshall_floyd inf = 10**18 inf 10**18 10 18 n = len(G) n len(G) len G [inf for i in range(n)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [inf for i in range(n)] d = [[inf for i in range(n)] for j in range(n)] d [[inf for i in range(n)] for j in range(n)] for i in range(n):
        d[i][i] = 0
        for j in G[i].keys():
            d[i][j] = G[i][j]
     i range(n) range n d[i][i] = 0 d[i][i] [i] d i i 0 for j in G[i].keys():
            d[i][j] = G[i][j]
     j G[i].keys() [i].keys [i] G i keys d[i][j] = G[i][j] d[i][j] [i] d i j G[i][j] [i] G i j for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
     k range(n) range n for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
     i range(n) range n for j in range(n):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
     j range(n) range n d[i][j] = min(d[i][j], d[i][k]+d[k][j]) d[i][j] [i] d i j min(d[i][j], d[i][k]+d[k][j]) min d[i][j] [i] d i j d[i][k]+d[k][j] d[i][k] [i] d i k d[k][j] [k] d k j return d d G G n, m, l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l {} for i in range(n) for i in range(n) i range(n) range n for i in range(n) {} G = [{} for i in range(n)] G [{} for i in range(n)] for j in range(m):
    a, b, c = map(int, input().split())
    G[a-1][b-1] = c
    G[b-1][a-1] = c j 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 G[a-1][b-1] = c G[a-1][b-1] [a-1] G a-1 a 1 b-1 b 1 c G[b-1][a-1] = c G[b-1][a-1] [b-1] G b-1 b 1 a-1 a 1 c D = warshall_floyd(G) D warshall_floyd(G) warshall_floyd G {} for i in range(n) for i in range(n) i range(n) range n for i in range(n) {} G = [{} for i in range(n)] G [{} for i in range(n)] for i in range(n):
    for j in range(n):
        if D[i][j] <= l:
            G[i][j] = 1 i range(n) range n for j in range(n):
        if D[i][j] <= l:
            G[i][j] = 1 j range(n) range n if D[i][j] <= l:
            G[i][j] = 1 D[i][j] <= l D[i][j] [i] D i j l G[i][j] = 1 G[i][j] [i] G i j 1 D = warshall_floyd(G) D warshall_floyd(G) warshall_floyd G for k in range(int(input())):
    s, t = map(int, input().split())
    if D[s-1][t-1] > 10**10:
        print(-1)
    else:
        print(D[s-1][t-1]-1) k range(int(input())) range int(input()) int input() input s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t if D[s-1][t-1] > 10**10:
        print(-1)
    else:
        print(D[s-1][t-1]-1) D[s-1][t-1] > 10**10 D[s-1][t-1] [s-1] D s-1 s 1 t-1 t 1 10**10 10 10 print(-1) print -1 print(D[s-1][t-1]-1) print D[s-1][t-1]-1 D[s-1][t-1] [s-1] D s-1 s 1 t-1 t 1 1 m, l = map(int, input().split()) map(int, input().split()) m a, b, c = map(int, input().split()) map(int, input().split()) a n, m, l = map(int, input().split()) map(int, input().split()) n b, c = map(int, input().split()) map(int, input().split()) b G = [{} for i in range(n)] [{} for i in range(n)] G def warshall_floyd(G):
    inf = 10**18
    # 重みつきグラフGに対してすべての頂点対の距離を求める
    n = len(G)
    d = [[inf for i in range(n)] for j in range(n)]
    for i in range(n):
        d[i][i] = 0
        for j in G[i].keys():
            d[i][j] = G[i][j]
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
    return d def warshall_floyd(G):
    inf = 10**18
    # 重みつきグラフGに対してすべての頂点対の距離を求める
    n = len(G)
    d = [[inf for i in range(n)] for j in range(n)]
    for i in range(n):
        d[i][i] = 0
        for j in G[i].keys():
            d[i][j] = G[i][j]
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
    return d warshall_floyd l = map(int, input().split()) map(int, input().split()) l D = warshall_floyd(G) warshall_floyd(G) D G = [{} for i in range(n)] [{} for i in range(n)] G D = warshall_floyd(G) warshall_floyd(G) D c = map(int, input().split()) map(int, input().split()) c t = map(int, input().split()) map(int, input().split()) t s, t = map(int, input().split()) map(int, input().split()) s
def warshall_floyd(G):
    inf = 10**18
    # 重みつきグラフGに対してすべての頂点対の距離を求める
    n = len(G)
    d = [[inf for i in range(n)] for j in range(n)]
    for i in range(n):
        d[i][i] = 0
        for j in G[i].keys():
            d[i][j] = G[i][j]
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
    return d


n, m, l = map(int, input().split())
G = [{} for i in range(n)]
for j in range(m):
    a, b, c = map(int, input().split())
    G[a-1][b-1] = c
    G[b-1][a-1] = c
D = warshall_floyd(G)
G = [{} for i in range(n)]
for i in range(n):
    for j in range(n):
        if D[i][j] <= l:
            G[i][j] = 1
D = warshall_floyd(G)
for k in range(int(input())):
    s, t = map(int, input().split())
    if D[s-1][t-1] > 10**10:
        print(-1)
    else:
        print(D[s-1][t-1]-1)
