def warshall_floyd(n, edges):
    d = [[float('inf')] * n for _ in range(n)]
    for i in range(n):
        d[i][i] = 0
    for vf, vt, w in edges:
        d[vf][vt] = w
    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())
edges = []
for _ in range(m):
    a, b, w = map(int, input().split())
    if w <= l:
        edges.append((a-1, b-1, w))
        edges.append((b-1, a-1, w))
wf = warshall_floyd(n, edges)

edges.clear()
for i in range(n):
    for j in range(i + 1, n):
        if wf[i][j] <= l:
            edges.append((i, j, 1))
            edges.append((j, i, 1))
wf = warshall_floyd(n, edges)

q = int(input())
ans = [0] * q
for i in range(q):
    s, t = map(lambda x:int(x) - 1, input().split())
    ans[i] = -1 if wf[s][t] == float('inf') else wf[s][t] - 1
for x in ans:
    print(x) def warshall_floyd(n, edges):
    d = [[float('inf')] * n for _ in range(n)]
    for i in range(n):
        d[i][i] = 0
    for vf, vt, w in edges:
        d[vf][vt] = w
    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 [float('inf')] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [float('inf')] * n [float('inf')] float('inf') float 'inf' n d = [[float('inf')] * n for _ in range(n)] d [[float('inf')] * n for _ in range(n)] for i in range(n):
        d[i][i] = 0
     i range(n) range n d[i][i] = 0 d[i][i] [i] d i i 0 for vf, vt, w in edges:
        d[vf][vt] = w
     vf vt w edges d[vf][vt] = w d[vf][vt] [vf] d vf vt w 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 n n edges edges n, m, l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l edges = [] edges [] for _ in range(m):
    a, b, w = map(int, input().split())
    if w <= l:
        edges.append((a-1, b-1, w))
        edges.append((b-1, a-1, w)) _ range(m) range m a, b, w = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b w if w <= l:
        edges.append((a-1, b-1, w))
        edges.append((b-1, a-1, w)) w <= l w l edges.append((a-1, b-1, w)) edges.append edges append (a-1, b-1, w) a-1 a 1 b-1 b 1 w edges.append((b-1, a-1, w)) edges.append edges append (b-1, a-1, w) b-1 b 1 a-1 a 1 w wf = warshall_floyd(n, edges) wf warshall_floyd(n, edges) warshall_floyd n edges edges.clear() edges.clear edges clear for i in range(n):
    for j in range(i + 1, n):
        if wf[i][j] <= l:
            edges.append((i, j, 1))
            edges.append((j, i, 1)) i range(n) range n for j in range(i + 1, n):
        if wf[i][j] <= l:
            edges.append((i, j, 1))
            edges.append((j, i, 1)) j range(i + 1, n) range i + 1 i 1 n if wf[i][j] <= l:
            edges.append((i, j, 1))
            edges.append((j, i, 1)) wf[i][j] <= l wf[i][j] [i] wf i j l edges.append((i, j, 1)) edges.append edges append (i, j, 1) i j 1 edges.append((j, i, 1)) edges.append edges append (j, i, 1) j i 1 wf = warshall_floyd(n, edges) wf warshall_floyd(n, edges) warshall_floyd n edges q = int(input()) q int(input()) int input() input ans = [0] * q ans [0] * q [0] 0 q for i in range(q):
    s, t = map(lambda x:int(x) - 1, input().split())
    ans[i] = -1 if wf[s][t] == float('inf') else wf[s][t] - 1 i range(q) range q s, t = map(lambda x:int(x) - 1, input().split()) s map(lambda x:int(x) - 1, input().split()) map lambda x:int(x) - 1 int(x) - 1 int(x) int x 1 x input().split() ().split () input split t ans[i] = -1 if wf[s][t] == float('inf') else wf[s][t] - 1 ans[i] ans i -1 if wf[s][t] == float('inf') else wf[s][t] - 1 wf[s][t] == float('inf') wf[s][t] [s] wf s t float('inf') float 'inf' -1 wf[s][t] - 1 wf[s][t] [s] wf s t 1 for x in ans:
    print(x) x ans print(x) print x t = map(lambda x:int(x) - 1, input().split()) map(lambda x:int(x) - 1, input().split()) t wf = warshall_floyd(n, edges) warshall_floyd(n, edges) wf w = map(int, input().split()) map(int, input().split()) w def warshall_floyd(n, edges):
    d = [[float('inf')] * n for _ in range(n)]
    for i in range(n):
        d[i][i] = 0
    for vf, vt, w in edges:
        d[vf][vt] = w
    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(n, edges):
    d = [[float('inf')] * n for _ in range(n)]
    for i in range(n):
        d[i][i] = 0
    for vf, vt, w in edges:
        d[vf][vt] = w
    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 ans = [0] * q [0] * q ans n, m, l = map(int, input().split()) map(int, input().split()) n a, b, w = map(int, input().split()) map(int, input().split()) a edges = [] [] edges m, l = map(int, input().split()) map(int, input().split()) m s, t = map(lambda x:int(x) - 1, input().split()) map(lambda x:int(x) - 1, input().split()) s wf = warshall_floyd(n, edges) warshall_floyd(n, edges) wf b, w = map(int, input().split()) map(int, input().split()) b l = map(int, input().split()) map(int, input().split()) l q = int(input()) int(input()) q
def warshall_floyd(n, edges):
    d = [[float('inf')] * n for _ in range(n)]
    for i in range(n):
        d[i][i] = 0
    for vf, vt, w in edges:
        d[vf][vt] = w
    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())
edges = []
for _ in range(m):
    a, b, w = map(int, input().split())
    if w <= l:
        edges.append((a-1, b-1, w))
        edges.append((b-1, a-1, w))
wf = warshall_floyd(n, edges)

edges.clear()
for i in range(n):
    for j in range(i + 1, n):
        if wf[i][j] <= l:
            edges.append((i, j, 1))
            edges.append((j, i, 1))
wf = warshall_floyd(n, edges)

q = int(input())
ans = [0] * q
for i in range(q):
    s, t = map(lambda x:int(x) - 1, input().split())
    ans[i] = -1 if wf[s][t] == float('inf') else wf[s][t] - 1
for x in ans:
    print(x)
