Recently Pashmak has been employed in a transportation company. The company has k buses and has a contract with a school which has n students. The school planned to take the students to d different places for d days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has to arrange the students in the buses. He wants to arrange the students in a way that no two students become close friends. In his ridiculous idea, two students will become close friends if and only if they are in the same buses for all d days.

Please help Pashmak with his weird idea. Assume that each bus has an unlimited capacity.


-----Input-----

The first line of input contains three space-separated integers n, k, d (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 10^9).


-----Output-----

If there is no valid arrangement just print -1. Otherwise print d lines, in each of them print n integers. The j-th integer of the i-th line shows which bus the j-th student has to take on the i-th day. You can assume that the buses are numbered from 1 to k.


-----Examples-----
Input
3 2 2

Output
1 1 2 
1 2 1 

Input
3 2 1

Output
-1



-----Note-----

Note that two students become close friends only if they share a bus each day. But the bus they share can differ from day to day.

Source: codeforces | Difficulty: HARD
Tags: Combinatorics

Mathematics

Constructive algorithms


Solutions:
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase

def main():
	(numOfStudents, numOfBuses, numOfDays) = [int(x) for x in input().split()]
	if numOfBuses ** numOfDays >= numOfStudents:
		studentSequences = [[1] * numOfDays for student in range(numOfStudents)]
		for student in range(numOfStudents):
			number = student
			for day in range(numOfDays):
				remainder = number % numOfBuses
				studentSequences[student][day] = remainder + 1
				number //= numOfBuses
				if number == 0:
					break
		for day in range(numOfDays):
			print(' '.join([str(studentSequences[student][day]) for student in range(numOfStudents)]))
	else:
		print(-1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
input = lambda : sys.stdin.readline().rstrip('\r\n')

def print(*args, **kwargs):
	sep = kwargs.pop('sep', ' ')
	file = kwargs.pop('file', sys.stdout)
	atStart = True
	for x in args:
		if not atStart:
			file.write(sep)
		file.write(str(x))
		atStart = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
main()


a = input()
b = a.split()
n = int(b[0])
k = int(b[1])
d = int(b[2])
if n > k ** d:
	print(-1)
	exit()
table = [[1] * d]
for i in range(n - 1):
	v = list(table[-1])
	j = len(v) - 1
	while v[j] == k:
		v[j] = 1
		j = j - 1
	v[j] = v[j] + 1
	table.append(v)
current_power = 1
answer = [0] * n
for m in range(0, d):
	current_value = 1
	for s in range(0, n):
		if s % current_power == 0 and s > 0:
			current_value = current_value % k + 1
		answer[s] = str(current_value)
	current_power *= k
	print(' '.join(answer))


(n, k, d) = map(int, input().split())
limit = 1
p = True
for i in range(d):
	limit *= k
	if limit >= n:
		p = False
		break
if p:
	print('-1')
	exit()
a = [i for i in range(1, n + 1)]
for i in range(d):
	b = ''
	for j in range(n):
		b += str(a[j] % k + 1) + ' '
		a[j] //= k
	print(b)


(n, k, d) = list(map(int, input().split()))
if k ** d < n:
	print(-1)
else:
	ans = []
	for i in range(d):
		ans.append([1 for j in range(n)])
	for i in range(n):
		j = 0
		p = i
		while p > 0:
			ans[j][i] = p % k + 1
			p = p // k
			j = j + 1
			if j == d:
				break
	for i in range(d):
		print(' '.join(map(str, ans[i])))


3
import sys
(n, k, d) = list(map(int, sys.stdin.readline().split()))
x = 1
while x ** d < n:
	x += 1
if x > k:
	sys.stdout.write('-1\n')
	return
ans = [[1 for i in range(n)] for j in range(d)]
for i in range(1, n):
	for j in range(d):
		ans[j][i] = ans[j][i - 1]
	ans[d - 1][i] += 1
	memo = 0
	for j in range(d - 1, -1, -1):
		ans[j][i] += memo
		memo = 0
		if ans[j][i] > x:
			memo = ans[j][i] - x
			ans[j][i] = 1
for i in range(d):
	sys.stdout.write(' '.join(map(str, ans[i])) + '\n')


(n, k, d) = map(int, input().split())
success = True
answer = [[] for x in range(n)]
answer[0] = [1 for x in range(d)]
for i_th_student in range(1, n):
	i_minus_one_student = answer[i_th_student - 1]
	current_student = list(i_minus_one_student)
	for i_th_day in reversed(range(d)):
		if i_minus_one_student[i_th_day] < k:
			current_student[i_th_day] += 1
			for i in range(i_th_day + 1, d):
				current_student[i] = 1
			break
	answer[i_th_student] = current_student
	if current_student == i_minus_one_student:
		success = False
		break
if not success:
	print('-1')
else:
	answer_trans = [[] for i in range(d)]
	for y in range(n):
		i = 0
		for x in answer[y]:
			answer_trans[i].append(x)
			i += 1
	for bla in answer_trans:
		print(' '.join(map(str, bla)))


import sys

def no():
	print(-1)
	sys.exit(0)
(n, k, d) = map(int, input().split())
if n <= k:
	for i in range(d):
		print(' '.join(map(str, range(1, n + 1))))
elif d == 1:
	no()
elif k == 1:
	no()
else:
	cur_step = 1
	arrangement = []
	while 1 + cur_step <= n:
		arrangement.append([])
		idx = 0
		for i in range(1, n + 1):
			arrangement[-1].append(idx + 1)
			if i % cur_step == 0:
				idx = (idx + 1) % k
		cur_step *= k
	if len(arrangement) > d:
		no()
	while len(arrangement) < d:
		arrangement.append([1] * n)
	print('\n'.join(map(lambda x: ' '.join(map(str, x)), arrangement)))


def add1(array, base):
	array[-1] += 1
	array = [0] + array
	k = len(array) - 1
	while array[k] >= base:
		array[k] -= base
		array[k - 1] += 1
		k -= 1
	if array[0] == 0:
		return array[1:]
	return array
(n, k, d) = list(map(int, input().split(' ')))
if n == 1:
	for i in range(d):
		print(1)
	quit()
if n > k ** d:
	print('-1')
	quit()
arr = []
array = [0] * d
for i in range(n):
	arr.append(array)
	array = add1(array[:], k)
new = [[0] * len(arr) for _ in range(len(arr[0]))]
for i in range(len(arr)):
	for j in range(len(arr[0])):
		new[j][i] = arr[i][j] + 1
for i in new:
	print(' '.join([str(x) for x in i]))


(n, k, d) = map(int, input().split())

def go(stu, j, ans, d, n, count):
	stu.append(str(j))
	if len(stu) == d:
		count.append([1])
		ans.append(' '.join(stu))
		stu.pop()
		return
	for i in range(1, k + 1):
		if len(count) >= n:
			break
		go(stu, i, ans, d, n, count)
	stu.pop()
if n > k ** d:
	print(-1)
else:
	ans = []
	count = []
	for j in range(1, k + 1):
		if len(count) >= n:
			break
		stu = []
		go(stu, j, ans, d, n, count)
	x = []
	for i in range(n):
		x.append(list(map(str, ans[i].split())))
	y = [[None for i in range(n)] for j in range(d)]
	for i in range(n):
		for j in range(d):
			y[j][i] = x[i][j]
	for i in range(d):
		print(' '.join(y[i]))


import os, sys
from io import BytesIO, IOBase

def base(x, k, d):
	ans = []
	while x:
		ans.append(x % k + 1)
		x //= k
	ans.reverse()
	return [1] * (d - len(ans)) + ans

def main():
	(n, k, d) = map(int, input().split())
	if n == 1:
		for _ in range(d):
			print(1)
		exit()
	if k == 1 or (d <= 10 and n > pow(k, d)):
		print(-1)
		exit()
	arr = [base(x, k, d) for x in range(n)]
	ans = [[0] * n for _ in range(d)]
	for i in range(n):
		for j in range(d):
			ans[j][i] = arr[i][j]
	for i in ans:
		print(*i)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, k, d) = list(map(int, input().split()))
if n > k ** d:
	print(-1)
	return
K = 1
for j in range(d):
	print(' '.join([str(i // K % k + 1) for i in range(n)]))
	K *= k


(n, k, d) = map(int, input().split())
p = 1
for i in range(d):
	p *= k
	if p >= n:
		break
s = [i for i in range(n)]
if n > p:
	print(-1)
else:
	for i in range(d):
		ans = ''
		for j in range(n):
			ans += str(s[j] % k + 1) + ' '
			s[j] //= k
		print(ans)


(n, k, d) = map(int, input().split())
if n > k ** d:
	print(-1)
	exit(0)
K = 1
for j in range(d):
	print(' '.join([str(i // K % k + 1) for i in range(n)]))
	K *= k


def main(inp):
	(n, k, d) = split_inp_int(inp)
	sols = []
	k = min(1000, k)
	import itertools
	source = itertools.product(*[range(1, k + 1) for __ in range(d)])
	for s in source:
		sols.append(s)
		if len(sols) == n:
			break
	if len(sols) < n:
		print(-1)
		return
	for i in range(d):
		for j in range(n):
			print(sols[j][i], end=' ')
		print()

def split_inp_int(inp):
	return list(map(int, inp().split()))

def use_fast_io():
	import sys

	class InputStorage:

		def __init__(self, lines):
			lines.reverse()
			self.lines = lines

		def input_func(self):
			if self.lines:
				return self.lines.pop()
			else:
				return ''
	input_storage_obj = InputStorage(sys.stdin.readlines())
	return input_storage_obj.input_func
from collections import Counter, defaultdict
from functools import reduce
import operator
import math

def product(arr_):
	return reduce(operator.mul, arr_, 1)
main(use_fast_io())


load = [int(i) for i in input().split()]
n = load[0]
k = load[1]
d = load[2]
p = 1
for i in range(d):
	p *= k
	if p >= n:
		break
if n > p:
	print(-1)
else:
	nums = [i for i in range(n)]
	for i in range(d):
		buff = ''
		for j in range(n):
			buff += str(nums[j] % k + 1) + ' '
			nums[j] //= k
		print(buff)


import time, math, bisect, sys
sys.setrecursionlimit(100000)
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 9 + 7

def solve():
	(n, k, d) = IP()
	if n > pow(k, d):
		print(-1)
		return
	else:
		li = [[0 for j in range(n)] for i in range(d)]
		student = 0
		for i in range(1, n):
			for j in range(d):
				li[j][i] = li[j][i - 1]
			for j in range(d):
				li[j][i] = (li[j][i] + 1) % k
				if li[j][i]:
					break
		for i in range(d):
			for j in range(n):
				print(int(li[i][j]) + 1, end=' ')
			print()
		return
solve()


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n, k, d) = I()
st = 0
ct = 0
if n <= k:
	for i in range(d):
		for j in range(n):
			print(j + 1, end=' ')
		print('')
	exit()
an = [[0] * n for i in range(d)]
tp = 1
s = 0
for i in range(d):
	tp *= k
	if tp >= n:
		s = 1
		break
if s:
	st = 0

	def conv(x):
		p = []
		while x:
			p.append(x % k)
			x //= k
		p = [0] * (d - len(p)) + p[::-1]
		return p
	for i in range(n):
		s = conv(st)
		for j in range(d - 1, -1, -1):
			an[j][i] = s[j] + 1
		st += 1
	for i in range(d):
		print(*an[i])
else:
	print(-1)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))
mod = 1000000007

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]

def YES():
	print('YES')

def NO():
	print('NO')

def Yes():
	print('Yes')

def No():
	print('No')
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

class MergeFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def lcm(a, b):
	return abs(a // gcd(a, b) * b)

def comb(n, r):
	if n < r:
		return 0
	else:
		return fac[n] * (finv[r] * finv[n - r] % mod) % mod

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def arr1d(n, v):
	return [v] * n

def arr2d(n, m, v):
	return [[v] * m for _ in range(n)]

def arr3d(n, m, p, v):
	return [[[v] * p for _ in range(m)] for i in range(n)]
ans = []

def solve():
	(n, k, d) = sep()
	if n > k ** d:
		print(-1)
		return
	cur = [1] * d
	for i in range(n):
		ans.append(cur.copy())
		for j in range(d - 1, -1, -1):
			if cur[j] == k:
				cur[j] = 1
			else:
				cur[j] += 1
				break
	for j in range(d):
		for i in range(n):
			print(ans[i][j], end=' ')
		print()
solve()


(n, k, d) = map(int, input().split())
if n > k ** d:
	print(-1)
	return
for i in range(d):
	power = k ** i
	resArray = [j // power % k + 1 for j in range(n)]
	print(' '.join(map(str, resArray)))


import sys
(n, k, d) = map(int, sys.stdin.readline().split())
no_sol = False
solution = [[1 for j in range(n)] for i in range(d)]

def schedule(i, j, level):
	global no_sol
	if level >= d:
		no_sol = True
		return
	count = j - i
	chunk = count // k
	extra = count % k
	r = i
	for t in range(min(k, count)):
		size = chunk + (1 if t < extra else 0)
		for z in range(size):
			solution[level][r + z] = t + 1
		if size > 1:
			schedule(r, r + size, level + 1)
		r += size
if k == 1:
	if n > 1:
		no_sol = True
else:
	schedule(0, n, 0)
if no_sol:
	print(-1)
else:
	for l in solution:
		print(' '.join((str(x) for x in l)))


(n, k, d) = list(map(int, input().split()))
ans = []
for i in range(d):
	tmp = [0] * n
	ans.append(tmp)
tmp = []

def add(val):
	pos = d - 1
	while pos >= 0:
		tmp[pos] += val
		if tmp[pos] == k:
			tmp[pos] = 0
			val = 1
		elif tmp[pos] > k:
			val = tmp[pos] - k
			tmp[pos] %= k
		else:
			val = 0
			break
		pos -= 1

def fill(col):
	cnt = 0
	for i in tmp:
		ans[cnt][col] = i
		cnt += 1
if k ** d < n:
	print('-1')
else:
	tmp = [0] * d
	for i in range(n):
		fill(i)
		add(1)
	for i in ans:
		for j in i:
			print(j + 1, end=' ')
		print()


(n, k, d) = map(int, input().split())
if k < n ** (1 / d):
	print(-1)
else:
	k1 = 1
	for i in range(d):
		print(' '.join(map(str, [j // k1 % k + 1 for j in range(n)])))
		k1 = k * k1


import copy
inp = list(map(int, input().split()))
(n, k, d) = (inp[0], inp[1], inp[2])
c = 0
ans = []

def rec(arr):
	global c
	if c >= n:
		return
	if len(arr) == d:
		c += 1
		ans.append(copy.deepcopy(arr))
		return
	temp = copy.deepcopy(arr)
	temp.append(0)
	for i in range(1, k + 1):
		if c >= n:
			break
		temp[-1] = i
		rec(temp)
if k ** d < n:
	print(-1)
else:
	rec([])
	a = [[0 for i in range(n)] for j in range(d)]
	for i in range(n):
		for j in range(d):
			a[j][i] = ans[i][j]
	for i in range(d):
		print(*a[i])


import fileinput
import math
for line in fileinput.input():
	inp = [int(i) for i in line.split()]
n = inp[0]
k = inp[1]
d = inp[2]
if n > k ** d:
	print(-1)
else:
	for i in range(d):
		pr = k ** i
		results = [j // pr % k + 1 for j in range(n)]
		print(' '.join(map(str, results)))


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
from typing import List

def bit(val, n, l):
	x = []
	while val > 0:
		x.append(val % n)
		val //= n
	return [0] * (l - len(x)) + x[::-1]

def solve(N, K, D):
	if math.log(N, K) > D or K ** D < N:
		print(-1)
		return
	a = []
	for i in range(N):
		x = bit(i, K, D)
		a.append(x)
	ans = []
	for d in range(D):
		ans.append(' '.join(map(str, [a[i][d] + 1 for i in range(N)])))
	print('\n'.join(ans))
(N, K, D) = map(int, input().split())
solve(N, K, D)


import math as mt
import collections as cc
I = lambda : list(map(int, input().split()))
(n, k, d) = I()
if n > k ** d:
	print(-1)
else:
	ans = [[0] * d for i in range(n)]
	for i in range(1, n):
		for j in range(d):
			ans[i][j] = ans[i - 1][j]
		for j in range(d - 1, -1, -1):
			ans[i][j] = (ans[i][j] + 1) % k
			if ans[i][j]:
				break
	for i in range(d):
		for j in range(n):
			print(ans[j][i] + 1, end=' ')
		print()


import math
(n, k, d) = map(int, input().split())
if k >= n:
	for i in range(d):
		print(' '.join([str(i) for i in range(1, n + 1)]))
elif math.log(n, k) > d:
	print(-1)
else:
	pk = 1
	for i in range(d):
		times = 0
		val = 1
		for j in range(n):
			if times < pk:
				print(val, end=' ')
				times += 1
			else:
				val += 1
				if val > k:
					val = 1
				times = 0
				print(val, end=' ')
				times += 1
		pk *= k
		print()


(n, k, d) = [int(k) for k in input().split()]
base_rep = [[0 for _ in range(d)] for _ in range(n)]
if k ** d < n:
	print(-1)
else:
	for j in range(n):
		num = j
		i = 0
		while num >= k ** i:
			i += 1
		i -= 1
		while num:
			base_rep[j - 1][i] = num // k ** i
			num = num % k ** i
			i -= 1
	for i in range(d):
		s = ''
		for j in range(n):
			s += str(base_rep[j][i] + 1) + ' '
		print(s)


m = list(input().split())
n = int(m[0])
k = int(m[1])
d = int(m[2])
if n == 1:
	for i in range(d):
		print('1')
	exit()
if k == 1:
	print('-1')
	exit()
if k >= n:
	m = list((i for i in range(n)))
	o = ''
	for j in range(1, n + 1):
		o += ' ' + str(j)
	o = o[1:]
	for i in range(d):
		print(o)
	exit()
if d == 1:
	print('-1')
	exit()
if d >= n:
	m = list(('1' for i in range(n)))
	for i in range(n):
		m[i] = '2'
		o = str(m[0])
		for j in range(1, n):
			o += ' ' + str(m[j])
		print(o)
	for i in range(n, d):
		print(o)
	exit()
from math import ceil, floor
tc = ceil(n / k)
tf = floor(n / k)
if n > k ** d:
	print('-1')
	exit()
sc = 1
for stp in range(1, d + 1):
	o = ''
	kc = 0
	while kc < n:
		for kk in range(1, k + 1):
			for i in range(sc):
				if kc < n:
					o += ' ' + str(kk)
					kc += 1
				else:
					break
	sc *= k
	print(o[1:])


import math
(n, k, d) = list(map(int, input().split()))
if n > k ** d:
	print(-1)
else:
	t = 1
	for i in range(d):
		li = []
		for j in range(n):
			li.append(j // t % k + 1)
		print(*li)
		t *= k


import sys

def main():
	(n, k, d) = map(int, sys.stdin.readline().split())
	blocksize = n
	for i in range(d):
		blocksize = blocksize // k + (blocksize % k != 0)
	if blocksize > 1:
		print('-1')
		return
	for days in range(d):
		i = 0
		bus = 1
		while i < n:
			for j in range(blocksize):
				sys.stdout.write(str(bus) + ' ')
				i += 1
				if i == n:
					break
			bus += 1
			if bus > k:
				bus = 1
		blocksize *= k
		sys.stdout.write('\n')

def __starting_point():
	main()
__starting_point()


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 10 ** 9 + 7
EPS = 1e-06

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, k, d) = value()
if n > k ** d:
	print(-1)
else:
	each = 1
	for i in range(d):
		key = 1
		c = 0
		for i in range(n):
			print(key, end=' ')
			c += 1
			if c == each:
				c = 0
				key += 1
				if key > k:
					key = 1
		each *= k
		print()


def f(t):
	i = -1
	t[i] += 1
	while t[i] > k:
		t[i] = 1
		i -= 1
		t[i] += 1
	return list(map(str, t))
(n, k, d) = map(int, input().split())
if k ** d < n:
	print(-1)
else:
	t = [1] * d
	t[-1] = 0
	s = [f(t) for i in range(n)]
	print('\n'.join([' '.join(t) for t in zip(*s)]))


(n, k, d) = list(map(int, input().split()))
if k ** d < n:
	print(-1)
else:
	for i in range(d):
		p = k ** i
		arr = [j // p % k + 1 for j in range(n)]
		print(' '.join(map(str, arr)))


import sys
input = sys.stdin.readline
(n, k, d) = map(int, input().split())
if n > k ** d:
	print(-1)
	exit()
x = 1
for i in range(d):
	ans = [1 + i // x % k for i in range(n)]
	print(*ans)
	x *= k


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
(n, k, d) = L()
if n > k ** d:
	print(-1)
	exit()
A = []
for i in range(n):
	x = []
	y = i
	for j in range(d):
		x.append(y % k + 1)
		y //= k
	A.append(x)
for i in range(d):
	for j in range(n):
		print(A[j][i], end=' ')
	print()
endtime = time.time()


(n, k, d) = map(int, input().split())
bits = n
for i in range(d):
	bits = bits // k + (bits % k != 0)
if bits > 1:
	print('-1')
	exit()
for _ in range(d):
	i = 0
	res = 1
	while i < n:
		for j in range(bits):
			print(res, end=' ')
			i += 1
			if i == n:
				break
		res += 1
		if res > k:
			res = 1
	bits *= k
	print()


from math import *
(n, k, d) = map(int, input().split())

def ff(n, k):
	if n % k != 0:
		return n % k
	else:
		return k

def f(n, k, feed):
	answer = []
	if n < k:
		for numbers in range(n):
			answer.append(numbers)
	else:
		x_1 = ceil(n / k)
		x_2 = floor(n / k)
		y_1 = n % k
		y_2 = k - n % k
		counter = 1
		for numbers in range(y_1):
			answer += x_1 * [counter]
			counter += 1
		for numbers in range(y_2):
			answer += x_2 * [counter]
			counter += 1
	new_answer = ''
	for elements in answer:
		new_answer += str(ff(elements, k)) + ' '
	return new_answer
if k == 1:
	if n == 1:
		for numbers in range(d):
			print(1)
	else:
		print(-1)
elif ceil(log(n, k)) > d:
	print(-1)
elif k >= n:
	answer = ''
	for numbers in range(1, n + 1):
		answer += str(numbers) + ' '
	for numbers in range(d):
		print(answer)
else:
	list_numbers = [n]
	for numbers in range(ceil(log(n, k))):
		list_new = []
		for elements in list_numbers:
			x_1 = ceil(elements / k)
			x_2 = floor(elements / k)
			y_1 = elements % k
			y_2 = k - elements % k
			list_new += [x_1] * y_1 + [x_2] * y_2
		feed = 1
		answer = ''
		for values in list_numbers:
			answer += f(values, k, feed)
			feed += 1
		print(answer)
		list_numbers = list_new
	for numbers in range(d - ceil(log(n, k))):
		print('1 ' * n)


(n, k, d) = map(int, input().split(' '))
if n > pow(k, d):
	print(-1)
else:
	raw = [' '] * n
	table = [[1] * d]
	p = 1
	for i in range(d):
		cv = 1
		for j in range(n):
			if j % p == 0 and j != 0:
				cv = cv + 1
				if cv == k + 1:
					cv = 1
			raw[j] = str(cv)
		print(' '.join(raw))
		p = p * k


import io
import os
import sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def printd(*args, **kwargs):
	pass

def get_str():
	return input().decode().strip()

def rint():
	return map(int, input().split())

def oint():
	return int(input())

def conv(i):
	ret = [1] * d
	for ii in range(d):
		ret[ii] = i % k + 1
		i //= k
		if i == 0:
			break
	return ret
(n, k, d) = rint()
printd(n, k, d)
if k ** d < n:
	print(-1)
	exit()
ans = [[0 for i in range(n)] for j in range(d)]
ans1 = []
for i in range(n):
	ans1.append(conv(i))
printd(ans)
printd(ans1)
for i in range(d):
	for j in range(n):
		ans[i][j] = ans1[j][i]
for i in range(d):
	print(*ans[i])


a = input()
b = a.split()
n = int(b[0])
k = int(b[1])
d = int(b[2])
raw = [' '] * n
if n > k ** d:
	print(-1)
	return
table = [[1] * d]
p = 1
for i in range(d):
	cv = 1
	for j in range(n):
		if j % p == 0 and j != 0:
			cv = cv + 1
			if cv == k + 1:
				cv = 1
		raw[j] = str(cv)
	print(' '.join(raw))
	p = p * k


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
import os
import sys
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, k, d) = map(int, input().split())
if n > k ** d:
	print(-1)
else:
	ans = [i for i in range(0, n)]
	for i in range(0, d):
		for j in range(0, n):
			print(ans[j] % k + 1, end=' ')
			ans[j] //= k
		print('')


from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
inf = float('inf')
from functools import cmp_to_key
from collections import defaultdict as dd
from collections import Counter, deque
from heapq import *
import math
from math import floor, ceil, sqrt

def geti():
	return map(int, input().strip().split())

def getl():
	return list(map(int, input().strip().split()))

def getis():
	return map(str, input().strip().split())

def getls():
	return list(map(str, input().strip().split()))

def gets():
	return input().strip()

def geta():
	return int(input())

def print_s(s):
	stdout.write(s + '\n')

def solve():
	(n, k, d) = geti()
	num = 1
	for i in range(1, d + 1):
		num *= k
		if num >= n:
			break
	else:
		print(-1)
		return

	def convert(prev):
		ans = prev[:]
		i = d - 1
		ans[i] += 1
		while ans[i] > k and i > 0:
			ans[i - 1] += 1
			ans[i] = 1
			i -= 1
		return ans
	ans = [[1] * d]
	for i in range(1, n + 1):
		ans.append(convert(ans[i - 1]))
	for i in range(d):
		print(*[ans[j][i] for j in range(n)])
solve()


(n, k, d) = map(int, input().split())
if n > pow(k, d):
	print(-1)
else:
	temp = []
	ans = [1] * d
	temp.append(ans)
	m = n
	m -= 1
	count = 1
	r = 1
	while m:
		ans = [0 for i in range(d)]
		count = r
		for i in range(d):
			ans[len(ans) - 1 - i] = count % k
			count = count // k
		for i in range(len(ans)):
			ans[i] += 1
		temp.append(ans)
		r += 1
		m -= 1
	for i in range(d):
		for j in range(len(temp)):
			print(temp[j][i], end=' ')
		print(' ')


import sys

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))
arr = get_ints()
n = arr[0]
k = arr[1]
d = arr[2]
maxs = pow(k, d)
if n > maxs:
	print(-1)
else:
	ans = []
	count = 0
	strs = ''
	numarr = []
	countarr = []
	for i in range(d):
		numarr.append(1)
		countarr.append(0)
	countarr[0] = -1
	flag = 1
	for ii in range(n):
		countarr[0] += 1
		flag = 0
		digit = countarr[0] + numarr[0]
		if digit <= k:
			subsubarr = []
			for i in range(d):
				subsubarr.append(str(countarr[i] + numarr[i]))
			subsubarr = subsubarr[::-1]
			subans = ''
			for subss in subsubarr:
				subans += subss
				subans += ' '
			ans.append(subans[:-1])
		else:
			finalarr = []
			nn = len(countarr)
			for j in range(nn):
				if countarr[j] + numarr[j] > k:
					countarr[j] = 0
					countarr[j + 1] += 1
			subsubarr = []
			for i in range(d):
				subsubarr.append(str(countarr[i] + numarr[i]))
			subsubarr = subsubarr[::-1]
			subans = ''
			for subss in subsubarr:
				subans += subss
				subans += ' '
			ans.append(subans[:-1])
	finalans = []
	for subans in ans:
		subs = subans.split(' ')
		finalans.append(subs)
	for i in range(d):
		substring = ''
		for subans in finalans:
			substring += subans[i]
			substring += ' '
		print(substring)


from sys import stdin
import copy

def solve(tc):
	(n, k, d) = map(int, stdin.readline().split())
	ok = False
	possibilities = 1
	for i in range(d):
		possibilities *= k
		if possibilities >= n:
			ok = True
			break
	if not ok:
		print(-1)
		return
	mat = [[0 for i in range(n)] for j in range(d)]
	for i in range(n):
		num = i
		p = 0
		while p < d and num:
			mat[p][i] = num % k + 1
			num //= k
			p += 1
		for j in range(p, d):
			mat[j][i] = mat[j][i] + 1
	for i in range(d):
		print(' '.join(map(lambda x: str(x), mat[i])))
tc = 1
solve(tc)


import sys

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, k, d) = get_ints()
if n > k ** d:
	print(-1)
	exit()
for i in range(d):
	power = k ** i
	resArray = [j // power % k + 1 for j in range(n)]
	print(' '.join(map(str, resArray)))


(n, k, d) = [int(x) for x in input().split()]
if n <= k:
	comb = [str(x + 1) for x in range(n)]
	for x in range(d):
		print(' '.join(comb))
elif k == 1:
	print(-1)
else:
	base = k
	exp = d
	if pow(base, exp) >= n:
		total = 1
		while total < n:
			total *= base
		count = 0
		while total > 0:
			total = total // base
			if total == 0:
				break
			count += 1
			out = []
			for y in range(n):
				out.append(y // total % base)
			print(' '.join([str(z + 1) for z in out]))
		for x in range(d - count):
			print(' '.join(['1' for x in range(n)]))
	else:
		print(-1)


(n, k, d) = map(int, input().split())
ans = [[0 for j in range(n)] for i in range(d)]
if any((1 for i in range(d) if k ** (i + 1) >= n)):
	for i in range(n):
		N = i
		for j in range(d):
			ans[j][i] = 1 + N % k
			N //= k
	for i in range(d):
		print(' '.join(map(str, ans[i])))
else:
	print(-1)