import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

import numpy as np

from scipy.sparse.csgraph import floyd_warshall

from scipy.sparse import csr_matrix



N, M, L = [int(_) for _ in readline().split()]

ABCQST = np.array(read().split(), dtype=np.int64)

ABC = ABCQST[:3 * M]

ST = ABCQST[3 * M + 1:]

A, B, C = ABC[::3], ABC[1::3], ABC[2::3]

S, T = ST[::2], ST[1::2]

G = csr_matrix((C, (A, B)), shape=(N + 1, N + 1))

G2 = floyd_warshall(G, directed=0)

G3 = np.full((N + 1, N + 1), np.inf)

np.fill_diagonal(G3, 0)

G3[G2 <= L] = 1

G4 = floyd_warshall(G3, directed=0)

G4[G4 == np.inf] = 0

print(*(G4.astype(np.int64)[S, T] - 1), sep='\n')

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

import numpy as np

from scipy.sparse.csgraph import floyd_warshall

from scipy.sparse import csr_matrix



N, M, L = [int(_) for _ in readline().split()]

ABCQST = np.array(read().split(), dtype=np.int64)

ABC = ABCQST[:3 * M]

ST = ABCQST[3 * M + 1:]

A, B, C = ABC[::3], ABC[1::3], ABC[2::3]

S, T = ST[::2], ST[1::2]

G = csr_matrix((C, (A, B)), shape=(N + 1, N + 1))

G2 = floyd_warshall(G, directed=0)

G3 = np.full((N + 1, N + 1), np.inf)

np.fill_diagonal(G3, 0)

G3[G2 <= L] = 1

G4 = floyd_warshall(G3, directed=0)

G4[G4 == np.inf] = 0

#print(*(G4.astype(int)[S, T] - 1), sep='\n')

print(('\n'.join((G4.astype(int)[S, T] - 1).astype(str))))

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

N, M, L = [int(_) for _ in readline().split()]
ABCQST = np.array(read().split(), dtype=np.int64)
ABC = ABCQST[: 3 * M]
ST = ABCQST[3 * M + 1 :]
A, B, C = ABC[::3], ABC[1::3], ABC[2::3]
S, T = ST[::2], ST[1::2]
G = csr_matrix((C, (A, B)), shape=(N + 1, N + 1))
G2 = floyd_warshall(G, directed=0)
G3 = np.full((N + 1, N + 1), np.inf)
np.fill_diagonal(G3, 0)
G3[G2 <= L] = 1
G4 = floyd_warshall(G3, directed=0)
G4[G4 == np.inf] = 0
print(*(G4.astype(np.int64)[S, T] - 1), sep="\n")

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

N, M, L = [int(_) for _ in readline().split()]
ABCQST = np.array(read().split(), dtype=np.int64)
ABC = ABCQST[: 3 * M]
ST = ABCQST[3 * M + 1 :]
A, B, C = ABC[::3], ABC[1::3], ABC[2::3]
S, T = ST[::2], ST[1::2]
G = csr_matrix((C, (A, B)), shape=(N + 1, N + 1))
G2 = floyd_warshall(G, directed=0)
G3 = np.full((N + 1, N + 1), np.inf)
np.fill_diagonal(G3, 0)
G3[G2 <= L] = 1
G4 = floyd_warshall(G3, directed=0)
G4[G4 == np.inf] = 0
# print(*(G4.astype(int)[S, T] - 1), sep='\n')
print(("\n".join((G4.astype(int)[S, T] - 1).astype(str))))

-print(*(G4.astype(np.int64)[S, T] - 1), sep="\n") +# print(*(G4.astype(int)[S, T] - 1), sep='\n') +print(("\n".join((G4.astype(int)[S, T] - 1).astype(str))))