inf = float('inf')

#計算量O(V^3) V:頂点数
# dist[i][j]: iからjへのコスト,  n:頂点数
def warshall_floyd(ad):
    n = len(ad)
    dist = [line[:] for line in ad]
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if i == j:
                    dist[i][j] = 0
                elif dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]
    return dist

N, M, L = map(int,input().split())
ad = [[inf] * N for _ in range(N)]
for _ in range(M):
    A, B, C = map(int,input().split())
    if C > L:
        continue
    A -= 1
    B -= 1
    ad[A][B] = C
    ad[B][A] = C
Q = int(input())
query = [[int(e)-1 for e in input().split()] for _ in range(Q)]

ad = warshall_floyd(ad)
for s in range(N):
    for t in range(N):
        if ad[s][t] <= L:
            ad[s][t] = 1
        else:
            ad[s][t] = inf

ad = warshall_floyd(ad)
for s, t in query:
    ans = ad[s][t] - 1
    if ans == inf:
        ans = -1
    print(ans) inf = float('inf') inf float('inf') float 'inf' def warshall_floyd(ad):
    n = len(ad)
    dist = [line[:] for line in ad]
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if i == j:
                    dist[i][j] = 0
                elif dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]
    return dist warshall_floyd n = len(ad) n len(ad) len ad line[:] for line in ad for line in ad line ad for line in ad line[:] line : dist = [line[:] for line in ad] dist [line[:] for line in ad] for k in range(n):
        for i in range(n):
            for j in range(n):
                if i == j:
                    dist[i][j] = 0
                elif dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]
     k range(n) range n for i in range(n):
            for j in range(n):
                if i == j:
                    dist[i][j] = 0
                elif dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]
     i range(n) range n for j in range(n):
                if i == j:
                    dist[i][j] = 0
                elif dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]
     j range(n) range n if i == j:
                    dist[i][j] = 0
                elif dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]
     i == j i j dist[i][j] = 0 dist[i][j] [i] dist i j 0 elif dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]
     dist[i][j] > dist[i][k] + dist[k][j] 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[i][j] = dist[i][k] + dist[k][j] 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 return dist dist ad ad N, M, L = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L [inf] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [inf] * N [inf] inf N ad = [[inf] * N for _ in range(N)] ad [[inf] * N for _ in range(N)] for _ in range(M):
    A, B, C = map(int,input().split())
    if C > L:
        continue
    A -= 1
    B -= 1
    ad[A][B] = C
    ad[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 if C > L:
        continue
     C > L C L continue A -= 1 A 1 B -= 1 B 1 ad[A][B] = C ad[A][B] [A] ad A B C ad[B][A] = C ad[B][A] [B] ad B A C Q = int(input()) Q int(input()) int input() input [int(e)-1 for e in input().split()] for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) [int(e)-1 for e in input().split()] query = [[int(e)-1 for e in input().split()] for _ in range(Q)] query [[int(e)-1 for e in input().split()] for _ in range(Q)] ad = warshall_floyd(ad) ad warshall_floyd(ad) warshall_floyd ad for s in range(N):
    for t in range(N):
        if ad[s][t] <= L:
            ad[s][t] = 1
        else:
            ad[s][t] = inf s range(N) range N for t in range(N):
        if ad[s][t] <= L:
            ad[s][t] = 1
        else:
            ad[s][t] = inf t range(N) range N if ad[s][t] <= L:
            ad[s][t] = 1
        else:
            ad[s][t] = inf ad[s][t] <= L ad[s][t] [s] ad s t L ad[s][t] = 1 ad[s][t] [s] ad s t 1 ad[s][t] = inf ad[s][t] [s] ad s t inf ad = warshall_floyd(ad) ad warshall_floyd(ad) warshall_floyd ad for s, t in query:
    ans = ad[s][t] - 1
    if ans == inf:
        ans = -1
    print(ans) s t query ans = ad[s][t] - 1 ans ad[s][t] - 1 ad[s][t] [s] ad s t 1 if ans == inf:
        ans = -1
     ans == inf ans inf ans = -1 ans -1 print(ans) print ans M, L = map(int,input().split()) map(int,input().split()) M ad = warshall_floyd(ad) warshall_floyd(ad) ad B -= 1 1 B Q = int(input()) int(input()) Q ad = [[inf] * N for _ in range(N)] [[inf] * N for _ in range(N)] ad def warshall_floyd(ad):
    n = len(ad)
    dist = [line[:] for line in ad]
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if i == j:
                    dist[i][j] = 0
                elif dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]
    return dist def warshall_floyd(ad):
    n = len(ad)
    dist = [line[:] for line in ad]
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if i == j:
                    dist[i][j] = 0
                elif dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]
    return dist warshall_floyd ad = warshall_floyd(ad) warshall_floyd(ad) ad N, M, L = map(int,input().split()) map(int,input().split()) N inf = float('inf') float('inf') inf A -= 1 1 A ans = -1 -1 ans ans = ad[s][t] - 1 ad[s][t] - 1 ans A, B, C = map(int,input().split()) map(int,input().split()) A query = [[int(e)-1 for e in input().split()] for _ in range(Q)] [[int(e)-1 for e in input().split()] for _ in range(Q)] query B, C = map(int,input().split()) map(int,input().split()) B C = map(int,input().split()) map(int,input().split()) C L = map(int,input().split()) map(int,input().split()) L
inf = float('inf')

#計算量O(V^3) V:頂点数
# dist[i][j]: iからjへのコスト,  n:頂点数
def warshall_floyd(ad):
    n = len(ad)
    dist = [line[:] for line in ad]
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if i == j:
                    dist[i][j] = 0
                elif dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]
    return dist

N, M, L = map(int,input().split())
ad = [[inf] * N for _ in range(N)]
for _ in range(M):
    A, B, C = map(int,input().split())
    if C > L:
        continue
    A -= 1
    B -= 1
    ad[A][B] = C
    ad[B][A] = C
Q = int(input())
query = [[int(e)-1 for e in input().split()] for _ in range(Q)]

ad = warshall_floyd(ad)
for s in range(N):
    for t in range(N):
        if ad[s][t] <= L:
            ad[s][t] = 1
        else:
            ad[s][t] = inf

ad = warshall_floyd(ad)
for s, t in query:
    ans = ad[s][t] - 1
    if ans == inf:
        ans = -1
    print(ans)