from enum import Enum
from queue import Queue

import numpy as np

import collections
import bisect
import sys
import math

from scipy.sparse.csgraph import floyd_warshall

BIG_NUM = 200000000000
MOD = 1000000007
EPS = 0.000000001

def warshall_floyd(d,n):
    #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,M,L = map(int,input().split())
d = [[float("inf") for i in range(N)] for j in range(N)]
for i in range(M):
    a,b,c = map(int,input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c
for i in range(N):
    d[i][i] = 0
d = floyd_warshall(d)
for i in range(N):
    for j in range(i,N):
        if d[i][j] <= L:
            d[i][j] = 1
            d[j][i] = 1
        else:
            d[i][j] = float("inf")
            d[j][i] = float("inf")
    d[i][i] = 1
d = floyd_warshall(d)
Q = int(input())
for q in range(Q):
    s,t = map(int,input().split())
    if d[s-1][t-1] == float("inf"):
        print(-1)
    else:
        print(int(d[s-1][t-1])-1) from enum import Enum from queue import Queue import numpy as np numpy import collections collections import bisect bisect import sys sys import math math from scipy.sparse.csgraph import floyd_warshall BIG_NUM = 200000000000 BIG_NUM 200000000000 MOD = 1000000007 MOD 1000000007 EPS = 0.000000001 EPS 0.000000001 def warshall_floyd(d,n):
    #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 n N,M,L = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L [float("inf") for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [float("inf") for i in range(N)] d = [[float("inf") for i in range(N)] for j in range(N)] d [[float("inf") for i in range(N)] for j in range(N)] for i in range(M):
    a,b,c = map(int,input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c i 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 d[a-1][b-1] = c d[a-1][b-1] [a-1] d a-1 a 1 b-1 b 1 c d[b-1][a-1] = c d[b-1][a-1] [b-1] d b-1 b 1 a-1 a 1 c 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 = floyd_warshall(d) d floyd_warshall(d) floyd_warshall d for i in range(N):
    for j in range(i,N):
        if d[i][j] <= L:
            d[i][j] = 1
            d[j][i] = 1
        else:
            d[i][j] = float("inf")
            d[j][i] = float("inf")
    d[i][i] = 1 i range(N) range N for j in range(i,N):
        if d[i][j] <= L:
            d[i][j] = 1
            d[j][i] = 1
        else:
            d[i][j] = float("inf")
            d[j][i] = float("inf")
     j range(i,N) range i N if d[i][j] <= L:
            d[i][j] = 1
            d[j][i] = 1
        else:
            d[i][j] = float("inf")
            d[j][i] = float("inf")
     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[j][i] = 1 d[j][i] [j] d j i 1 d[i][j] = float("inf") d[i][j] [i] d i j float("inf") float "inf" d[j][i] = float("inf") d[j][i] [j] d j i float("inf") float "inf" d[i][i] = 1 d[i][i] [i] d i i 1 d = floyd_warshall(d) d floyd_warshall(d) floyd_warshall d Q = int(input()) Q int(input()) int input() input for q in range(Q):
    s,t = map(int,input().split())
    if d[s-1][t-1] == float("inf"):
        print(-1)
    else:
        print(int(d[s-1][t-1])-1) q range(Q) range Q s,t = map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t if d[s-1][t-1] == float("inf"):
        print(-1)
    else:
        print(int(d[s-1][t-1])-1) d[s-1][t-1] == float("inf") d[s-1][t-1] [s-1] d s-1 s 1 t-1 t 1 float("inf") float "inf" print(-1) print -1 print(int(d[s-1][t-1])-1) print int(d[s-1][t-1])-1 int(d[s-1][t-1]) int d[s-1][t-1] [s-1] d s-1 s 1 t-1 t 1 1 BIG_NUM = 200000000000 200000000000 BIG_NUM d = [[float("inf") for i in range(N)] for j in range(N)] [[float("inf") for i in range(N)] for j in range(N)] d c = map(int,input().split()) map(int,input().split()) c Q = int(input()) int(input()) Q L = map(int,input().split()) map(int,input().split()) L d = floyd_warshall(d) floyd_warshall(d) d t = map(int,input().split()) map(int,input().split()) t M,L = map(int,input().split()) map(int,input().split()) M d = floyd_warshall(d) floyd_warshall(d) d N,M,L = map(int,input().split()) map(int,input().split()) N def warshall_floyd(d,n):
    #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,n):
    #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 s,t = map(int,input().split()) map(int,input().split()) s EPS = 0.000000001 0.000000001 EPS a,b,c = map(int,input().split()) map(int,input().split()) a MOD = 1000000007 1000000007 MOD b,c = map(int,input().split()) map(int,input().split()) b
from enum import Enum
from queue import Queue

import numpy as np

import collections
import bisect
import sys
import math

from scipy.sparse.csgraph import floyd_warshall

BIG_NUM = 200000000000
MOD = 1000000007
EPS = 0.000000001

def warshall_floyd(d,n):
    #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,M,L = map(int,input().split())
d = [[float("inf") for i in range(N)] for j in range(N)]
for i in range(M):
    a,b,c = map(int,input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c
for i in range(N):
    d[i][i] = 0
d = floyd_warshall(d)
for i in range(N):
    for j in range(i,N):
        if d[i][j] <= L:
            d[i][j] = 1
            d[j][i] = 1
        else:
            d[i][j] = float("inf")
            d[j][i] = float("inf")
    d[i][i] = 1
d = floyd_warshall(d)
Q = int(input())
for q in range(Q):
    s,t = map(int,input().split())
    if d[s-1][t-1] == float("inf"):
        print(-1)
    else:
        print(int(d[s-1][t-1])-1)
