n, m, L = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]
q = int(input())
st = [list(map(int, input().split())) for _ in range(q)]

d = [[float('inf') for _ in range(n)] for _ in range(n)]
for a, b, c in abc:
    if c > L:
        continue
    d[a-1][b-1] = c
    d[b-1][a-1] = c

def warshall_floyd(d):
    for k in range(n):
        for i in range(n):
            if i == k or d[i][k] > L:
                continue
            for j in range(n):
                if i == j:
                    continue
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

warshall_floyd(d)

for i in range(n):
    for j in range(n):
        if i == j:
            continue
        elif d[i][j] <= L:
            d[i][j] = 1
        else:
            d[i][j] = float('inf')

warshall_floyd(d)

for s, t in st:
    if d[s-1][t-1] == float('inf'):
        print(-1)
    else:
        print(d[s-1][t-1] - 1) n, m, L = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m L list(map(int, input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split abc = [list(map(int, input().split())) for _ in range(m)] abc [list(map(int, input().split())) for _ in range(m)] 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 st = [list(map(int, input().split())) for _ in range(q)] st [list(map(int, input().split())) for _ in range(q)] [float('inf') for _ in range(n)] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [float('inf') for _ in range(n)] d = [[float('inf') for _ in range(n)] for _ in range(n)] d [[float('inf') for _ in range(n)] for _ in range(n)] for a, b, c in abc:
    if c > L:
        continue
    d[a-1][b-1] = c
    d[b-1][a-1] = c a b c abc if c > L:
        continue
     c > L c L continue 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 def warshall_floyd(d):
    for k in range(n):
        for i in range(n):
            if i == k or d[i][k] > L:
                continue
            for j in range(n):
                if i == j:
                    continue
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d warshall_floyd for k in range(n):
        for i in range(n):
            if i == k or d[i][k] > L:
                continue
            for j in range(n):
                if i == j:
                    continue
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
     k range(n) range n for i in range(n):
            if i == k or d[i][k] > L:
                continue
            for j in range(n):
                if i == j:
                    continue
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
     i range(n) range n if i == k or d[i][k] > L:
                continue
             i == k or d[i][k] > L i == k i k d[i][k] > L d[i][k] [i] d i k L continue for j in range(n):
                if i == j:
                    continue
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
     j range(n) range n if i == j:
                    continue
                 i == j i j continue 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 d d warshall_floyd(d) warshall_floyd d for i in range(n):
    for j in range(n):
        if i == j:
            continue
        elif d[i][j] <= L:
            d[i][j] = 1
        else:
            d[i][j] = float('inf') i range(n) range n for j in range(n):
        if i == j:
            continue
        elif d[i][j] <= L:
            d[i][j] = 1
        else:
            d[i][j] = float('inf') j range(n) range n if i == j:
            continue
        elif d[i][j] <= L:
            d[i][j] = 1
        else:
            d[i][j] = float('inf') i == j i j continue elif d[i][j] <= L:
            d[i][j] = 1
         d[i][j] <= L d[i][j] [i] d i j L d[i][j] = 1 d[i][j] [i] d i j 1 d[i][j] = float('inf') d[i][j] [i] d i j float('inf') float 'inf' warshall_floyd(d) warshall_floyd d for s, t in st:
    if d[s-1][t-1] == float('inf'):
        print(-1)
    else:
        print(d[s-1][t-1] - 1) s t st if d[s-1][t-1] == float('inf'):
        print(-1)
    else:
        print(d[s-1][t-1] - 1) d[s-1][t-1] == float('inf') d[s-1][t-1] [s-1] d s-1 s 1 t-1 t 1 float('inf') float 'inf' 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 abc = [list(map(int, input().split())) for _ in range(m)] [list(map(int, input().split())) for _ in range(m)] abc def warshall_floyd(d):
    for k in range(n):
        for i in range(n):
            if i == k or d[i][k] > L:
                continue
            for j in range(n):
                if i == j:
                    continue
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d def warshall_floyd(d):
    for k in range(n):
        for i in range(n):
            if i == k or d[i][k] > L:
                continue
            for j in range(n):
                if i == j:
                    continue
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d warshall_floyd m, L = map(int, input().split()) map(int, input().split()) m st = [list(map(int, input().split())) for _ in range(q)] [list(map(int, input().split())) for _ in range(q)] st d = [[float('inf') for _ in range(n)] for _ in range(n)] [[float('inf') for _ in range(n)] for _ in range(n)] d n, m, L = map(int, input().split()) map(int, input().split()) n q = int(input()) int(input()) q L = map(int, input().split()) map(int, input().split()) L
n, m, L = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]
q = int(input())
st = [list(map(int, input().split())) for _ in range(q)]

d = [[float('inf') for _ in range(n)] for _ in range(n)]
for a, b, c in abc:
    if c > L:
        continue
    d[a-1][b-1] = c
    d[b-1][a-1] = c

def warshall_floyd(d):
    for k in range(n):
        for i in range(n):
            if i == k or d[i][k] > L:
                continue
            for j in range(n):
                if i == j:
                    continue
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

warshall_floyd(d)

for i in range(n):
    for j in range(n):
        if i == j:
            continue
        elif d[i][j] <= L:
            d[i][j] = 1
        else:
            d[i][j] = float('inf')

warshall_floyd(d)

for s, t in st:
    if d[s-1][t-1] == float('inf'):
        print(-1)
    else:
        print(d[s-1][t-1] - 1)
