import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def read_into(*A):
    for a, v in zip(A, read_ints()):
        a.append(v)


def solve():
    N, M, L = read_ints()
    dist = [
        [math.inf for _ in range(N)] for _ in range(N)
    ]
    for i in range(N):
        dist[i][i] = 0
    for _ in range(M):
        a, b, c = read_ints()
        dist[a-1][b-1] = dist[b-1][a-1] = c
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j])
    for i in range(N):
        for j in range(N):
            if i == j: continue
            dist[i][j] = 1 if dist[i][j] <= L else math.inf
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j])
    Q = read_int()
    for _ in range(Q):
        s, t = read_ints()
        if dist[s-1][t-1] == math.inf:
            print(-1)
        else:
            print(dist[s-1][t-1]-1)


if __name__ == '__main__':
    solve() import math math def read_int():
    return int(input().strip()) read_int return int(input().strip()) int(input().strip()) int input().strip() ().strip () input strip def read_ints():
    return list(map(int, input().strip().split(' '))) read_ints return list(map(int, input().strip().split(' '))) list(map(int, input().strip().split(' '))) list map(int, input().strip().split(' ')) map int input().strip().split(' ') ().strip().split ().strip() ().strip () input strip split ' ' def read_into(*A):
    for a, v in zip(A, read_ints()):
        a.append(v) read_into for a, v in zip(A, read_ints()):
        a.append(v) a v zip(A, read_ints()) zip A read_ints() read_ints a.append(v) a.append a append v *A def solve():
    N, M, L = read_ints()
    dist = [
        [math.inf for _ in range(N)] for _ in range(N)
    ]
    for i in range(N):
        dist[i][i] = 0
    for _ in range(M):
        a, b, c = read_ints()
        dist[a-1][b-1] = dist[b-1][a-1] = c
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j])
    for i in range(N):
        for j in range(N):
            if i == j: continue
            dist[i][j] = 1 if dist[i][j] <= L else math.inf
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j])
    Q = read_int()
    for _ in range(Q):
        s, t = read_ints()
        if dist[s-1][t-1] == math.inf:
            print(-1)
        else:
            print(dist[s-1][t-1]-1) solve N, M, L = read_ints() N read_ints() read_ints M L [math.inf for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [math.inf for _ in range(N)] dist = [
        [math.inf for _ in range(N)] for _ in range(N)
    ] dist [
        [math.inf for _ in range(N)] for _ in range(N)
    ] for i in range(N):
        dist[i][i] = 0
     i range(N) range N dist[i][i] = 0 dist[i][i] [i] dist i i 0 for _ in range(M):
        a, b, c = read_ints()
        dist[a-1][b-1] = dist[b-1][a-1] = c
     _ range(M) range M a, b, c = read_ints() a read_ints() read_ints b c dist[a-1][b-1] = dist[b-1][a-1] = c dist[a-1][b-1] [a-1] dist a-1 a 1 b-1 b 1 c = dist[b-1][a-1] = c dist[b-1][a-1] [b-1] dist b-1 b 1 a-1 a 1 c for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j])
     k range(N) range N for i in range(N):
            for j in range(N):
                dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j])
     i range(N) range N for j in range(N):
                dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j])
     j range(N) range N dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j]) dist[i][j] [i] dist i j min(dist[i][j], dist[i][k]+dist[k][j]) min dist[i][j] [i] dist i j dist[i][k]+dist[k][j] dist[i][k] [i] dist i k dist[k][j] [k] dist k j = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j]) dist[j][i] [j] dist j i min(dist[i][j], dist[i][k]+dist[k][j]) for i in range(N):
        for j in range(N):
            if i == j: continue
            dist[i][j] = 1 if dist[i][j] <= L else math.inf
     i range(N) range N for j in range(N):
            if i == j: continue
            dist[i][j] = 1 if dist[i][j] <= L else math.inf
     j range(N) range N if i == j: continue
             i == j i j dist[i][j] = 1 if dist[i][j] <= L else math.inf dist[i][j] [i] dist i j 1 if dist[i][j] <= L else math.inf dist[i][j] <= L dist[i][j] [i] dist i j L 1 math.inf math inf for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j])
     k range(N) range N for i in range(N):
            for j in range(N):
                dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j])
     i range(N) range N for j in range(N):
                dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j])
     j range(N) range N dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j]) dist[i][j] [i] dist i j min(dist[i][j], dist[i][k]+dist[k][j]) min dist[i][j] [i] dist i j dist[i][k]+dist[k][j] dist[i][k] [i] dist i k dist[k][j] [k] dist k j = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j]) dist[j][i] [j] dist j i min(dist[i][j], dist[i][k]+dist[k][j]) Q = read_int() Q read_int() read_int for _ in range(Q):
        s, t = read_ints()
        if dist[s-1][t-1] == math.inf:
            print(-1)
        else:
            print(dist[s-1][t-1]-1) _ range(Q) range Q s, t = read_ints() s read_ints() read_ints t if dist[s-1][t-1] == math.inf:
            print(-1)
        else:
            print(dist[s-1][t-1]-1) dist[s-1][t-1] == math.inf dist[s-1][t-1] [s-1] dist s-1 s 1 t-1 t 1 math.inf math inf print(-1) print -1 print(dist[s-1][t-1]-1) print dist[s-1][t-1]-1 dist[s-1][t-1] [s-1] dist s-1 s 1 t-1 t 1 1 if __name__ == '__main__':
    solve() __name__ == '__main__' __name__ '__main__' solve() solve def read_into(*A):
    for a, v in zip(A, read_ints()):
        a.append(v) def read_into(*A):
    for a, v in zip(A, read_ints()):
        a.append(v) read_into def solve():
    N, M, L = read_ints()
    dist = [
        [math.inf for _ in range(N)] for _ in range(N)
    ]
    for i in range(N):
        dist[i][i] = 0
    for _ in range(M):
        a, b, c = read_ints()
        dist[a-1][b-1] = dist[b-1][a-1] = c
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j])
    for i in range(N):
        for j in range(N):
            if i == j: continue
            dist[i][j] = 1 if dist[i][j] <= L else math.inf
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j])
    Q = read_int()
    for _ in range(Q):
        s, t = read_ints()
        if dist[s-1][t-1] == math.inf:
            print(-1)
        else:
            print(dist[s-1][t-1]-1) def solve():
    N, M, L = read_ints()
    dist = [
        [math.inf for _ in range(N)] for _ in range(N)
    ]
    for i in range(N):
        dist[i][i] = 0
    for _ in range(M):
        a, b, c = read_ints()
        dist[a-1][b-1] = dist[b-1][a-1] = c
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j])
    for i in range(N):
        for j in range(N):
            if i == j: continue
            dist[i][j] = 1 if dist[i][j] <= L else math.inf
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j])
    Q = read_int()
    for _ in range(Q):
        s, t = read_ints()
        if dist[s-1][t-1] == math.inf:
            print(-1)
        else:
            print(dist[s-1][t-1]-1) solve def read_ints():
    return list(map(int, input().strip().split(' '))) def read_ints():
    return list(map(int, input().strip().split(' '))) read_ints def read_int():
    return int(input().strip()) def read_int():
    return int(input().strip()) read_int
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def read_into(*A):
    for a, v in zip(A, read_ints()):
        a.append(v)


def solve():
    N, M, L = read_ints()
    dist = [
        [math.inf for _ in range(N)] for _ in range(N)
    ]
    for i in range(N):
        dist[i][i] = 0
    for _ in range(M):
        a, b, c = read_ints()
        dist[a-1][b-1] = dist[b-1][a-1] = c
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j])
    for i in range(N):
        for j in range(N):
            if i == j: continue
            dist[i][j] = 1 if dist[i][j] <= L else math.inf
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j])
    Q = read_int()
    for _ in range(Q):
        s, t = read_ints()
        if dist[s-1][t-1] == math.inf:
            print(-1)
        else:
            print(dist[s-1][t-1]-1)


if __name__ == '__main__':
    solve()
