def warshall_floyd(n,d):
    #d[i][j]: iからjへの最短距離
    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
##############################
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(0)

N, M, L = LI()
d = [[float("inf") for i in range(N)] for i in range(N)]
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(M):
    x,y,z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z
for i in range(N):
    d[i][i] = 0 #自身のところに行くコストは０
#print(warshall_floyd(N,d))
cur = warshall_floyd(N,d)
newD = [[float("inf") for i in range(N)] for i in range(N)]
for i in range(N):
    for l,j in enumerate(cur[i]):
        if j<=L:
            newD[i][l] = 1
            newD[l][i]

ansC = warshall_floyd(N,newD)

Q = I()
for i in range(Q):
    s, t = LI()
    ans = ansC[s-1][t-1]-1
    if ans==inf:
        ans = -1
    print(ans) def warshall_floyd(n,d):
    #d[i][j]: iからjへの最短距離
    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 n n d d import sys sys def I(): return int(sys.stdin.readline()) I def LI(): return list(map(int,sys.stdin.readline().split())) LI mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 inf = float('inf') inf float('inf') float 'inf' ans = int(0) ans int(0) int 0 N, M, L = LI() N LI() LI M L [float("inf") for i in range(N)] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [float("inf") for i in range(N)] d = [[float("inf") for i in range(N)] for i in range(N)] d [[float("inf") for i in range(N)] for i in range(N)] for i in range(M):
    x,y,z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z i range(M) range M x,y,z = map(int,input().split()) x map(int,input().split()) map int input().split() ().split () input split y z d[x-1][y-1] = z d[x-1][y-1] [x-1] d x-1 x 1 y-1 y 1 z d[y-1][x-1] = z d[y-1][x-1] [y-1] d y-1 y 1 x-1 x 1 z for i in range(N):
    d[i][i] = 0 #自身のところに行くコストは０
#print(warshall_floyd(N,d)) i range(N) range N d[i][i] = 0 d[i][i] [i] d i i 0 cur = warshall_floyd(N,d) cur warshall_floyd(N,d) warshall_floyd N d [float("inf") for i in range(N)] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [float("inf") for i in range(N)] newD = [[float("inf") for i in range(N)] for i in range(N)] newD [[float("inf") for i in range(N)] for i in range(N)] for i in range(N):
    for l,j in enumerate(cur[i]):
        if j<=L:
            newD[i][l] = 1
            newD[l][i] i range(N) range N for l,j in enumerate(cur[i]):
        if j<=L:
            newD[i][l] = 1
            newD[l][i] l j enumerate(cur[i]) enumerate cur[i] cur i if j<=L:
            newD[i][l] = 1
            newD[l][i] j<=L j L newD[i][l] = 1 newD[i][l] [i] newD i l 1 newD[l][i] [l] newD l i ansC = warshall_floyd(N,newD) ansC warshall_floyd(N,newD) warshall_floyd N newD Q = I() Q I() I for i in range(Q):
    s, t = LI()
    ans = ansC[s-1][t-1]-1
    if ans==inf:
        ans = -1
    print(ans) i range(Q) range Q s, t = LI() s LI() LI t ans = ansC[s-1][t-1]-1 ans ansC[s-1][t-1]-1 ansC[s-1][t-1] [s-1] ansC s-1 s 1 t-1 t 1 1 if ans==inf:
        ans = -1
     ans==inf ans inf ans = -1 ans -1 print(ans) print ans ans = -1 -1 ans z = map(int,input().split()) map(int,input().split()) z ans = int(0) int(0) ans s, t = LI() LI() s newD = [[float("inf") for i in range(N)] for i in range(N)] [[float("inf") for i in range(N)] for i in range(N)] newD def warshall_floyd(n,d):
    #d[i][j]: iからjへの最短距離
    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(n,d):
    #d[i][j]: iからjへの最短距離
    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 Q = I() I() Q def LI(): return list(map(int,sys.stdin.readline().split())) def LI(): return list(map(int,sys.stdin.readline().split())) LI inf = float('inf') float('inf') inf ansC = warshall_floyd(N,newD) warshall_floyd(N,newD) ansC x,y,z = map(int,input().split()) map(int,input().split()) x N, M, L = LI() LI() N L = LI() LI() L def I(): return int(sys.stdin.readline()) def I(): return int(sys.stdin.readline()) I d = [[float("inf") for i in range(N)] for i in range(N)] [[float("inf") for i in range(N)] for i in range(N)] d t = LI() LI() t cur = warshall_floyd(N,d) warshall_floyd(N,d) cur ans = ansC[s-1][t-1]-1 ansC[s-1][t-1]-1 ans mod = 10**9 + 7 10**9 + 7 mod M, L = LI() LI() M y,z = map(int,input().split()) map(int,input().split()) y
def warshall_floyd(n,d):
    #d[i][j]: iからjへの最短距離
    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
##############################
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(0)

N, M, L = LI()
d = [[float("inf") for i in range(N)] for i in range(N)]
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(M):
    x,y,z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z
for i in range(N):
    d[i][i] = 0 #自身のところに行くコストは０
#print(warshall_floyd(N,d))
cur = warshall_floyd(N,d)
newD = [[float("inf") for i in range(N)] for i in range(N)]
for i in range(N):
    for l,j in enumerate(cur[i]):
        if j<=L:
            newD[i][l] = 1
            newD[l][i]

ansC = warshall_floyd(N,newD)

Q = I()
for i in range(Q):
    s, t = LI()
    ans = ansC[s-1][t-1]-1
    if ans==inf:
        ans = -1
    print(ans)