INF = 10 ** 9
n, m, l = map(int, input().split())
d = [[INF for j in range(n + 1)] for i in range(n + 1)]
d2 = [[INF for j in range(n + 1)] for i in range(n + 1)]
for _ in range(m):
    i, j, c = map(int, input().split())
    d[i][j] = c
    d[j][i] = c
    if c <= l:
        d2[i][j] = 1
        d2[j][i] = 1

q = int(input())
Q = [list(map(int, input().split())) for _ in range(q)]

for k in range(1, n + 1):
    for i in range(1, n):
        for j in range(i, n + 1):
            dk = d[i][k] + d[k][j]
            if d[i][j] > dk:
                d[i][j] = dk
                d[j][i] = dk
                if dk <= l:
                    d2[i][j] = 1
                    d2[j][i] = 1

for k in range(1, n + 1):
    for i in range(1, n):
        for j in range(i, n + 1):
            dk = d2[i][k] + d2[k][j]
            if d2[i][j] > dk:
                d2[i][j] = dk
                d2[j][i] = dk

for i in range(q):
    s, t = Q[i]
    di = d2[s][t]
    if di >= INF:
        print(-1)
    else:
        print(di - 1) INF = 10 ** 9 INF 10 ** 9 10 9 n, m, l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l [INF for j in range(n + 1)] for i in range(n + 1) for i in range(n + 1) i range(n + 1) range n + 1 n 1 for i in range(n + 1) [INF for j in range(n + 1)] d = [[INF for j in range(n + 1)] for i in range(n + 1)] d [[INF for j in range(n + 1)] for i in range(n + 1)] [INF for j in range(n + 1)] for i in range(n + 1) for i in range(n + 1) i range(n + 1) range n + 1 n 1 for i in range(n + 1) [INF for j in range(n + 1)] d2 = [[INF for j in range(n + 1)] for i in range(n + 1)] d2 [[INF for j in range(n + 1)] for i in range(n + 1)] for _ in range(m):
    i, j, c = map(int, input().split())
    d[i][j] = c
    d[j][i] = c
    if c <= l:
        d2[i][j] = 1
        d2[j][i] = 1 _ range(m) range m i, j, c = map(int, input().split()) i map(int, input().split()) map int input().split() ().split () input split j c d[i][j] = c d[i][j] [i] d i j c d[j][i] = c d[j][i] [j] d j i c if c <= l:
        d2[i][j] = 1
        d2[j][i] = 1 c <= l c l d2[i][j] = 1 d2[i][j] [i] d2 i j 1 d2[j][i] = 1 d2[j][i] [j] d2 j i 1 q = int(input()) q int(input()) int input() input list(map(int, input().split())) for _ in range(q) for _ in range(q) _ range(q) range q for _ in range(q) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split Q = [list(map(int, input().split())) for _ in range(q)] Q [list(map(int, input().split())) for _ in range(q)] for k in range(1, n + 1):
    for i in range(1, n):
        for j in range(i, n + 1):
            dk = d[i][k] + d[k][j]
            if d[i][j] > dk:
                d[i][j] = dk
                d[j][i] = dk
                if dk <= l:
                    d2[i][j] = 1
                    d2[j][i] = 1 k range(1, n + 1) range 1 n + 1 n 1 for i in range(1, n):
        for j in range(i, n + 1):
            dk = d[i][k] + d[k][j]
            if d[i][j] > dk:
                d[i][j] = dk
                d[j][i] = dk
                if dk <= l:
                    d2[i][j] = 1
                    d2[j][i] = 1 i range(1, n) range 1 n for j in range(i, n + 1):
            dk = d[i][k] + d[k][j]
            if d[i][j] > dk:
                d[i][j] = dk
                d[j][i] = dk
                if dk <= l:
                    d2[i][j] = 1
                    d2[j][i] = 1 j range(i, n + 1) range i n + 1 n 1 dk = d[i][k] + d[k][j] dk d[i][k] + d[k][j] d[i][k] [i] d i k d[k][j] [k] d k j if d[i][j] > dk:
                d[i][j] = dk
                d[j][i] = dk
                if dk <= l:
                    d2[i][j] = 1
                    d2[j][i] = 1 d[i][j] > dk d[i][j] [i] d i j dk d[i][j] = dk d[i][j] [i] d i j dk d[j][i] = dk d[j][i] [j] d j i dk if dk <= l:
                    d2[i][j] = 1
                    d2[j][i] = 1 dk <= l dk l d2[i][j] = 1 d2[i][j] [i] d2 i j 1 d2[j][i] = 1 d2[j][i] [j] d2 j i 1 for k in range(1, n + 1):
    for i in range(1, n):
        for j in range(i, n + 1):
            dk = d2[i][k] + d2[k][j]
            if d2[i][j] > dk:
                d2[i][j] = dk
                d2[j][i] = dk k range(1, n + 1) range 1 n + 1 n 1 for i in range(1, n):
        for j in range(i, n + 1):
            dk = d2[i][k] + d2[k][j]
            if d2[i][j] > dk:
                d2[i][j] = dk
                d2[j][i] = dk i range(1, n) range 1 n for j in range(i, n + 1):
            dk = d2[i][k] + d2[k][j]
            if d2[i][j] > dk:
                d2[i][j] = dk
                d2[j][i] = dk j range(i, n + 1) range i n + 1 n 1 dk = d2[i][k] + d2[k][j] dk d2[i][k] + d2[k][j] d2[i][k] [i] d2 i k d2[k][j] [k] d2 k j if d2[i][j] > dk:
                d2[i][j] = dk
                d2[j][i] = dk d2[i][j] > dk d2[i][j] [i] d2 i j dk d2[i][j] = dk d2[i][j] [i] d2 i j dk d2[j][i] = dk d2[j][i] [j] d2 j i dk for i in range(q):
    s, t = Q[i]
    di = d2[s][t]
    if di >= INF:
        print(-1)
    else:
        print(di - 1) i range(q) range q s, t = Q[i] s Q[i] Q i t di = d2[s][t] di d2[s][t] [s] d2 s t if di >= INF:
        print(-1)
    else:
        print(di - 1) di >= INF di INF print(-1) print -1 print(di - 1) print di - 1 di 1 INF = 10 ** 9 10 ** 9 INF q = int(input()) int(input()) q Q = [list(map(int, input().split())) for _ in range(q)] [list(map(int, input().split())) for _ in range(q)] Q dk = d2[i][k] + d2[k][j] d2[i][k] + d2[k][j] dk d = [[INF for j in range(n + 1)] for i in range(n + 1)] [[INF for j in range(n + 1)] for i in range(n + 1)] d s, t = Q[i] Q[i] s t = Q[i] Q[i] t m, l = map(int, input().split()) map(int, input().split()) m l = map(int, input().split()) map(int, input().split()) l j, c = map(int, input().split()) map(int, input().split()) j di = d2[s][t] d2[s][t] di n, m, l = map(int, input().split()) map(int, input().split()) n c = map(int, input().split()) map(int, input().split()) c i, j, c = map(int, input().split()) map(int, input().split()) i dk = d[i][k] + d[k][j] d[i][k] + d[k][j] dk d2 = [[INF for j in range(n + 1)] for i in range(n + 1)] [[INF for j in range(n + 1)] for i in range(n + 1)] d2
INF = 10 ** 9
n, m, l = map(int, input().split())
d = [[INF for j in range(n + 1)] for i in range(n + 1)]
d2 = [[INF for j in range(n + 1)] for i in range(n + 1)]
for _ in range(m):
    i, j, c = map(int, input().split())
    d[i][j] = c
    d[j][i] = c
    if c <= l:
        d2[i][j] = 1
        d2[j][i] = 1

q = int(input())
Q = [list(map(int, input().split())) for _ in range(q)]

for k in range(1, n + 1):
    for i in range(1, n):
        for j in range(i, n + 1):
            dk = d[i][k] + d[k][j]
            if d[i][j] > dk:
                d[i][j] = dk
                d[j][i] = dk
                if dk <= l:
                    d2[i][j] = 1
                    d2[j][i] = 1

for k in range(1, n + 1):
    for i in range(1, n):
        for j in range(i, n + 1):
            dk = d2[i][k] + d2[k][j]
            if d2[i][j] > dk:
                d2[i][j] = dk
                d2[j][i] = dk

for i in range(q):
    s, t = Q[i]
    di = d2[s][t]
    if di >= INF:
        print(-1)
    else:
        print(di - 1)
