INF = 10**10

def warshall_floyd(d):
    # d[i][j]: ij間の最小コスト
    # i=jのとき0, i!=jのときINFで初期化
    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())
dist = [[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 = map(int, input().split())
    a -= 1; b -= 1
    dist[a][b] = c; dist[b][a] = c
dist = warshall_floyd(dist)

dist2 = [[INF for _ in range(N)] for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i == j:
            dist2[i][i] = 0
        else:
            if dist[i][j] <= L:
                dist2[i][j] = 1
dist2 = warshall_floyd(dist2)

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1; t -= 1
    if dist2[s][t] == INF:
        print(-1)
    else:
        print(dist2[s][t]-1) INF = 10**10 INF 10**10 10 10 def warshall_floyd(d):
    # d[i][j]: ij間の最小コスト
    # i=jのとき0, i!=jのときINFで初期化
    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 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 d d N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L [INF for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF for _ in range(N)] dist = [[INF for _ in range(N)] for _ in range(N)] dist [[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 = map(int, input().split())
    a -= 1; b -= 1
    dist[a][b] = c; dist[b][a] = c _ 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 a -= 1 a 1 b -= 1 b 1 dist[a][b] = c dist[a][b] [a] dist a b c dist[b][a] = c dist[b][a] [b] dist b a c dist = warshall_floyd(dist) dist warshall_floyd(dist) warshall_floyd dist [INF for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF for _ in range(N)] dist2 = [[INF for _ in range(N)] for _ in range(N)] dist2 [[INF for _ in range(N)] for _ in range(N)] for i in range(N):
    for j in range(N):
        if i == j:
            dist2[i][i] = 0
        else:
            if dist[i][j] <= L:
                dist2[i][j] = 1 i range(N) range N for j in range(N):
        if i == j:
            dist2[i][i] = 0
        else:
            if dist[i][j] <= L:
                dist2[i][j] = 1 j range(N) range N if i == j:
            dist2[i][i] = 0
        else:
            if dist[i][j] <= L:
                dist2[i][j] = 1 i == j i j dist2[i][i] = 0 dist2[i][i] [i] dist2 i i 0 if dist[i][j] <= L:
                dist2[i][j] = 1 dist[i][j] <= L dist[i][j] [i] dist i j L dist2[i][j] = 1 dist2[i][j] [i] dist2 i j 1 dist2 = warshall_floyd(dist2) dist2 warshall_floyd(dist2) warshall_floyd dist2 Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1; t -= 1
    if dist2[s][t] == INF:
        print(-1)
    else:
        print(dist2[s][t]-1) _ range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t s -= 1 s 1 t -= 1 t 1 if dist2[s][t] == INF:
        print(-1)
    else:
        print(dist2[s][t]-1) dist2[s][t] == INF dist2[s][t] [s] dist2 s t INF print(-1) print -1 print(dist2[s][t]-1) print dist2[s][t]-1 dist2[s][t] [s] dist2 s t 1 INF = 10**10 10**10 INF c = map(int, input().split()) map(int, input().split()) c b -= 1 1 b a, b, c = map(int, input().split()) map(int, input().split()) a def warshall_floyd(d):
    # d[i][j]: ij間の最小コスト
    # i=jのとき0, i!=jのときINFで初期化
    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(d):
    # d[i][j]: ij間の最小コスト
    # i=jのとき0, i!=jのときINFで初期化
    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 dist2 = warshall_floyd(dist2) warshall_floyd(dist2) dist2 t = map(int, input().split()) map(int, input().split()) t b, c = map(int, input().split()) map(int, input().split()) b L = map(int, input().split()) map(int, input().split()) L dist = warshall_floyd(dist) warshall_floyd(dist) dist s, t = map(int, input().split()) map(int, input().split()) s s -= 1 1 s a -= 1 1 a Q = int(input()) int(input()) Q M, L = map(int, input().split()) map(int, input().split()) M dist = [[INF for _ in range(N)] for _ in range(N)] [[INF for _ in range(N)] for _ in range(N)] dist dist2 = [[INF for _ in range(N)] for _ in range(N)] [[INF for _ in range(N)] for _ in range(N)] dist2 t -= 1 1 t N, M, L = map(int, input().split()) map(int, input().split()) N
INF = 10**10

def warshall_floyd(d):
    # d[i][j]: ij間の最小コスト
    # i=jのとき0, i!=jのときINFで初期化
    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())
dist = [[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 = map(int, input().split())
    a -= 1; b -= 1
    dist[a][b] = c; dist[b][a] = c
dist = warshall_floyd(dist)

dist2 = [[INF for _ in range(N)] for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i == j:
            dist2[i][i] = 0
        else:
            if dist[i][j] <= L:
                dist2[i][j] = 1
dist2 = warshall_floyd(dist2)

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1; t -= 1
    if dist2[s][t] == INF:
        print(-1)
    else:
        print(dist2[s][t]-1)