from heapq import *
INF = 1e10

def floyd(n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]

N,M,L = map(int,input().split())

d = [[INF]*N for i in range(N)]

for x in range(M):
    a,b,w = map(int,input().split())
    d[a-1][b-1] = w
    d[b-1][a-1] = w

floyd(N)

grafo2 = [[INF] * N for i in range(N)]

for x in range(N):
    for y in range(N) :
        if d[x][y] <= L:
            grafo2[x][y] = 1

for k in range(N):
    for i in range(N):
        for j in range(N):
            if grafo2[i][j] > grafo2[i][k] + grafo2[k][j]:
                grafo2[i][j] = grafo2[i][k] + grafo2[k][j]

query = int(input())

for x in range(query):
    s,t = map(int,input().split())
    if grafo2[s-1][t-1] == INF:
        print(-1)
    else:
        print(grafo2[s-1][t-1] - 1) from heapq import * INF = 1e10 INF 1e10 def floyd(n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j] floyd for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j] k range(n) range n for i in range(n):
            for j in range(n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j] i range(n) range n for j in range(n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j] j range(n) range n if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j] d[i][j] > d[i][k] + d[k][j] 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 d[i][j] = d[i][k] + d[k][j] 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 n n N,M,L = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L [INF]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [INF]*N [INF] INF N d = [[INF]*N for i in range(N)] d [[INF]*N for i in range(N)] for x in range(M):
    a,b,w = map(int,input().split())
    d[a-1][b-1] = w
    d[b-1][a-1] = w x range(M) range M a,b,w = map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b w d[a-1][b-1] = w d[a-1][b-1] [a-1] d a-1 a 1 b-1 b 1 w d[b-1][a-1] = w d[b-1][a-1] [b-1] d b-1 b 1 a-1 a 1 w floyd(N) floyd N [INF] * N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [INF] * N [INF] INF N grafo2 = [[INF] * N for i in range(N)] grafo2 [[INF] * N for i in range(N)] for x in range(N):
    for y in range(N) :
        if d[x][y] <= L:
            grafo2[x][y] = 1 x range(N) range N for y in range(N) :
        if d[x][y] <= L:
            grafo2[x][y] = 1 y range(N) range N if d[x][y] <= L:
            grafo2[x][y] = 1 d[x][y] <= L d[x][y] [x] d x y L grafo2[x][y] = 1 grafo2[x][y] [x] grafo2 x y 1 for k in range(N):
    for i in range(N):
        for j in range(N):
            if grafo2[i][j] > grafo2[i][k] + grafo2[k][j]:
                grafo2[i][j] = grafo2[i][k] + grafo2[k][j] k range(N) range N for i in range(N):
        for j in range(N):
            if grafo2[i][j] > grafo2[i][k] + grafo2[k][j]:
                grafo2[i][j] = grafo2[i][k] + grafo2[k][j] i range(N) range N for j in range(N):
            if grafo2[i][j] > grafo2[i][k] + grafo2[k][j]:
                grafo2[i][j] = grafo2[i][k] + grafo2[k][j] j range(N) range N if grafo2[i][j] > grafo2[i][k] + grafo2[k][j]:
                grafo2[i][j] = grafo2[i][k] + grafo2[k][j] grafo2[i][j] > grafo2[i][k] + grafo2[k][j] grafo2[i][j] [i] grafo2 i j grafo2[i][k] + grafo2[k][j] grafo2[i][k] [i] grafo2 i k grafo2[k][j] [k] grafo2 k j grafo2[i][j] = grafo2[i][k] + grafo2[k][j] grafo2[i][j] [i] grafo2 i j grafo2[i][k] + grafo2[k][j] grafo2[i][k] [i] grafo2 i k grafo2[k][j] [k] grafo2 k j query = int(input()) query int(input()) int input() input for x in range(query):
    s,t = map(int,input().split())
    if grafo2[s-1][t-1] == INF:
        print(-1)
    else:
        print(grafo2[s-1][t-1] - 1) x range(query) range query s,t = map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t if grafo2[s-1][t-1] == INF:
        print(-1)
    else:
        print(grafo2[s-1][t-1] - 1) grafo2[s-1][t-1] == INF grafo2[s-1][t-1] [s-1] grafo2 s-1 s 1 t-1 t 1 INF print(-1) print -1 print(grafo2[s-1][t-1] - 1) print grafo2[s-1][t-1] - 1 grafo2[s-1][t-1] [s-1] grafo2 s-1 s 1 t-1 t 1 1 def floyd(n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j] def floyd(n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j] floyd t = map(int,input().split()) map(int,input().split()) t w = map(int,input().split()) map(int,input().split()) w grafo2 = [[INF] * N for i in range(N)] [[INF] * N for i in range(N)] grafo2 a,b,w = map(int,input().split()) map(int,input().split()) a s,t = map(int,input().split()) map(int,input().split()) s M,L = map(int,input().split()) map(int,input().split()) M N,M,L = map(int,input().split()) map(int,input().split()) N INF = 1e10 1e10 INF L = map(int,input().split()) map(int,input().split()) L b,w = map(int,input().split()) map(int,input().split()) b query = int(input()) int(input()) query d = [[INF]*N for i in range(N)] [[INF]*N for i in range(N)] d
from heapq import *
INF = 1e10

def floyd(n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]

N,M,L = map(int,input().split())

d = [[INF]*N for i in range(N)]

for x in range(M):
    a,b,w = map(int,input().split())
    d[a-1][b-1] = w
    d[b-1][a-1] = w

floyd(N)

grafo2 = [[INF] * N for i in range(N)]

for x in range(N):
    for y in range(N) :
        if d[x][y] <= L:
            grafo2[x][y] = 1

for k in range(N):
    for i in range(N):
        for j in range(N):
            if grafo2[i][j] > grafo2[i][k] + grafo2[k][j]:
                grafo2[i][j] = grafo2[i][k] + grafo2[k][j]

query = int(input())

for x in range(query):
    s,t = map(int,input().split())
    if grafo2[s-1][t-1] == INF:
        print(-1)
    else:
        print(grafo2[s-1][t-1] - 1)
