import sys
input = sys.stdin.readline

N,M,L = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in [0]*M]
Q = int(input())
ST = [list(map(int,input().split())) for _ in [0]*Q]


INF = (L+1)*N
d = [[INF]*N for _ in [0]*N]
for i in range(N):
    d[i][i] = 0
for a,b,c in ABC:
    a-=1;b-=1
    d[a][b] = c
    d[b][a] = c

def Warshall_Floyd(d,N=None):
    if N==None : N = len(d)
    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])

Warshall_Floyd(d,N)

d2 = [None]*N
for i,row in enumerate(d):
    d2[i] = [1 if e<=L else INF for e in row]
    d2[i][i] = 0

Warshall_Floyd(d2,N)

for s,t in ST:
    s-=1;t-=1
    ans = (d2[s][t]%INF)-1
    print(ans) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N,M,L = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L list(map(int,input().split())) for _ in [0]*M for _ in [0]*M _ [0]*M [0] 0 M for _ in [0]*M list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split ABC = [list(map(int,input().split())) for _ in [0]*M] ABC [list(map(int,input().split())) for _ in [0]*M] Q = int(input()) Q int(input()) int input() input list(map(int,input().split())) for _ in [0]*Q for _ in [0]*Q _ [0]*Q [0] 0 Q for _ in [0]*Q list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split ST = [list(map(int,input().split())) for _ in [0]*Q] ST [list(map(int,input().split())) for _ in [0]*Q] INF = (L+1)*N INF (L+1)*N L+1 L 1 N [INF]*N for _ in [0]*N for _ in [0]*N _ [0]*N [0] 0 N for _ in [0]*N [INF]*N [INF] INF N d = [[INF]*N for _ in [0]*N] d [[INF]*N for _ in [0]*N] 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 for a,b,c in ABC:
    a-=1;b-=1
    d[a][b] = c
    d[b][a] = c a b c ABC a-=1 a 1 b-=1 b 1 d[a][b] = c d[a][b] [a] d a b c d[b][a] = c d[b][a] [b] d b a c def Warshall_Floyd(d,N=None):
    if N==None : N = len(d)
    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]) Warshall_Floyd if N==None : N = len(d)
     N==None N None 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 d d N=None N None Warshall_Floyd(d,N) Warshall_Floyd d N d2 = [None]*N d2 [None]*N [None] None N for i,row in enumerate(d):
    d2[i] = [1 if e<=L else INF for e in row]
    d2[i][i] = 0 i row enumerate(d) enumerate d 1 if e<=L else INF for e in row for e in row e row for e in row 1 if e<=L else INF e<=L e L 1 INF d2[i] = [1 if e<=L else INF for e in row] d2[i] d2 i [1 if e<=L else INF for e in row] d2[i][i] = 0 d2[i][i] [i] d2 i i 0 Warshall_Floyd(d2,N) Warshall_Floyd d2 N for s,t in ST:
    s-=1;t-=1
    ans = (d2[s][t]%INF)-1
    print(ans) s t ST s-=1 s 1 t-=1 t 1 ans = (d2[s][t]%INF)-1 ans (d2[s][t]%INF)-1 d2[s][t]%INF d2[s][t] [s] d2 s t INF 1 print(ans) print ans Q = int(input()) int(input()) Q L = map(int,input().split()) map(int,input().split()) L b-=1 1 b def Warshall_Floyd(d,N=None):
    if N==None : N = len(d)
    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]) def Warshall_Floyd(d,N=None):
    if N==None : N = len(d)
    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]) Warshall_Floyd M,L = map(int,input().split()) map(int,input().split()) M d2 = [None]*N [None]*N d2 s-=1 1 s t-=1 1 t input = sys.stdin.readline sys.stdin.readline input ans = (d2[s][t]%INF)-1 (d2[s][t]%INF)-1 ans INF = (L+1)*N (L+1)*N INF ABC = [list(map(int,input().split())) for _ in [0]*M] [list(map(int,input().split())) for _ in [0]*M] ABC N,M,L = map(int,input().split()) map(int,input().split()) N ST = [list(map(int,input().split())) for _ in [0]*Q] [list(map(int,input().split())) for _ in [0]*Q] ST d = [[INF]*N for _ in [0]*N] [[INF]*N for _ in [0]*N] d a-=1 1 a
import sys
input = sys.stdin.readline

N,M,L = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in [0]*M]
Q = int(input())
ST = [list(map(int,input().split())) for _ in [0]*Q]


INF = (L+1)*N
d = [[INF]*N for _ in [0]*N]
for i in range(N):
    d[i][i] = 0
for a,b,c in ABC:
    a-=1;b-=1
    d[a][b] = c
    d[b][a] = c

def Warshall_Floyd(d,N=None):
    if N==None : N = len(d)
    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])

Warshall_Floyd(d,N)

d2 = [None]*N
for i,row in enumerate(d):
    d2[i] = [1 if e<=L else INF for e in row]
    d2[i][i] = 0

Warshall_Floyd(d2,N)

for s,t in ST:
    s-=1;t-=1
    ans = (d2[s][t]%INF)-1
    print(ans)