inf = 10 ** 10

########ワーシャルフロイド法

def warshall_floyd(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

##############################
n,w,L = map(int,input().split()) #n:頂点数　w:辺の数

d = [[inf for i in range(n)] for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(w):
    x,y,z = map(int,input().split())
    x -= 1
    y -= 1
    d[x][y] = z
    d[y][x] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
d = warshall_floyd(d)

D = [[inf for i in range(n)] for i in range(n)]

for i in range(n):
    for j in range(n):
        if i == j:
            D[i][j] = 0
        elif d[i][j] <= L:
            D[i][j] = 1

D = warshall_floyd(D)

Q = int(input())
for i in range(Q):
    s,t = map(int,input().split())
    s -= 1
    t -= 1
    if D[s][t] == inf:
        print(-1)
    else:
        print(D[s][t]-1)


         inf = 10 ** 10 inf 10 ** 10 10 10 def warshall_floyd(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 d d n,w,L = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split w L [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) [inf for i in range(n)] d = [[inf for i in range(n)] for i in range(n)] d [[inf for i in range(n)] for i in range(n)] for i in range(w):
    x,y,z = map(int,input().split())
    x -= 1
    y -= 1
    d[x][y] = z
    d[y][x] = z i range(w) range w x,y,z = map(int,input().split()) x map(int,input().split()) map int input().split() ().split () input split y z x -= 1 x 1 y -= 1 y 1 d[x][y] = z d[x][y] [x] d x y z d[y][x] = z d[y][x] [y] d y x z for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０ i range(n) range n d[i][i] = 0 d[i][i] [i] d i i 0 d = warshall_floyd(d) d warshall_floyd(d) warshall_floyd d [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) [inf for i in range(n)] D = [[inf for i in range(n)] for i in range(n)] D [[inf for i in range(n)] for i in range(n)] for i in range(n):
    for j in range(n):
        if i == j:
            D[i][j] = 0
        elif d[i][j] <= L:
            D[i][j] = 1 i range(n) range n for j in range(n):
        if i == j:
            D[i][j] = 0
        elif d[i][j] <= L:
            D[i][j] = 1 j range(n) range n if i == j:
            D[i][j] = 0
        elif d[i][j] <= L:
            D[i][j] = 1 i == j i j D[i][j] = 0 D[i][j] [i] D i j 0 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 = warshall_floyd(D) D warshall_floyd(D) warshall_floyd D Q = int(input()) Q int(input()) int input() input for i in range(Q):
    s,t = map(int,input().split())
    s -= 1
    t -= 1
    if D[s][t] == inf:
        print(-1)
    else:
        print(D[s][t]-1)


         i 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 D[s][t] == inf:
        print(-1)
    else:
        print(D[s][t]-1)


         D[s][t] == inf D[s][t] [s] D s t inf print(-1) print -1 print(D[s][t]-1) print D[s][t]-1 D[s][t] [s] D s t 1 w,L = map(int,input().split()) map(int,input().split()) w Q = int(input()) int(input()) Q y,z = map(int,input().split()) map(int,input().split()) y D = warshall_floyd(D) warshall_floyd(D) D d = [[inf for i in range(n)] for i in range(n)] [[inf for i in range(n)] for i in range(n)] d inf = 10 ** 10 10 ** 10 inf z = map(int,input().split()) map(int,input().split()) z def warshall_floyd(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(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 L = map(int,input().split()) map(int,input().split()) L t = map(int,input().split()) map(int,input().split()) t t -= 1 1 t x,y,z = map(int,input().split()) map(int,input().split()) x D = [[inf for i in range(n)] for i in range(n)] [[inf for i in range(n)] for i in range(n)] D s -= 1 1 s d = warshall_floyd(d) warshall_floyd(d) d x -= 1 1 x y -= 1 1 y n,w,L = map(int,input().split()) map(int,input().split()) n s,t = map(int,input().split()) map(int,input().split()) s
inf = 10 ** 10

########ワーシャルフロイド法

def warshall_floyd(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

##############################
n,w,L = map(int,input().split()) #n:頂点数　w:辺の数

d = [[inf for i in range(n)] for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(w):
    x,y,z = map(int,input().split())
    x -= 1
    y -= 1
    d[x][y] = z
    d[y][x] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
d = warshall_floyd(d)

D = [[inf for i in range(n)] for i in range(n)]

for i in range(n):
    for j in range(n):
        if i == j:
            D[i][j] = 0
        elif d[i][j] <= L:
            D[i][j] = 1

D = warshall_floyd(D)

Q = int(input())
for i in range(Q):
    s,t = map(int,input().split())
    s -= 1
    t -= 1
    if D[s][t] == inf:
        print(-1)
    else:
        print(D[s][t]-1)


        
