The Hat is a game of speedy explanation/guessing words (similar to Alias). It's fun. Try it! In this problem, we are talking about a variant of the game when the players are sitting at the table and everyone plays individually (i.e. not teams, but individual gamers play).

$n$ people gathered in a room with $m$ tables ($n \ge 2m$). They want to play the Hat $k$ times. Thus, $k$ games will be played at each table. Each player will play in $k$ games.

To do this, they are distributed among the tables for each game. During each game, one player plays at exactly one table. A player can play at different tables.

Players want to have the most "fair" schedule of games. For this reason, they are looking for a schedule (table distribution for each game) such that:

At any table in each game there are either $\lfloor\frac{n}{m}\rfloor$ people or $\lceil\frac{n}{m}\rceil$ people (that is, either $n/m$ rounded down, or $n/m$ rounded up). Different numbers of people can play different games at the same table.

Let's calculate for each player the value $b_i$ — the number of times the $i$-th player played at a table with $\lceil\frac{n}{m}\rceil$ persons ($n/m$ rounded up). Any two values of $b_i$must differ by no more than $1$. In other words, for any two players $i$ and $j$, it must be true $|b_i - b_j| \le 1$.

For example, if $n=5$, $m=2$ and $k=2$, then at the request of the first item either two players or three players should play at each table. Consider the following schedules:

First game: $1, 2, 3$ are played at the first table, and $4, 5$ at the second one. The second game: at the first table they play $5, 1$, and at the second  — $2, 3, 4$. This schedule is not "fair" since $b_2=2$ (the second player played twice at a big table) and $b_5=0$ (the fifth player did not play at a big table).

First game: $1, 2, 3$ are played at the first table, and $4, 5$ at the second one. The second game: at the first table they play $4, 5, 2$, and at the second one  — $1, 3$. This schedule is "fair": $b=[1,2,1,1,1]$ (any two values of $b_i$ differ by no more than $1$).

Find any "fair" game schedule for $n$ people if they play on the $m$ tables of $k$ games.


-----Input-----

The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.

Each test case consists of one line that contains three integers $n$, $m$ and $k$ ($2 \le n \le 2\cdot10^5$, $1 \le m \le \lfloor\frac{n}{2}\rfloor$, $1 \le k \le 10^5$) — the number of people, tables and games, respectively.

It is guaranteed that the sum of $nk$ ($n$ multiplied by $k$) over all test cases does not exceed $2\cdot10^5$.


-----Output-----

For each test case print a required schedule  — a sequence of $k$ blocks of $m$ lines. Each block corresponds to one game, a line in a block corresponds to one table. In each line print the number of players at the table and the indices of the players (numbers from $1$ to $n$) who should play at this table.

If there are several required schedules, then output any of them. We can show that a valid solution always exists.

You can output additional blank lines to separate responses to different sets of inputs.


-----Examples-----

Input
3
5 2 2
8 3 1
2 1 3
Output
3 1 2 3
2 4 5
3 4 5 2
2 1 3

2 6 2
3 3 5 1
3 4 7 8

2 2 1
2 2 1
2 2 1


-----Note-----

None

Source: codeforces | Difficulty: HARD
Tags: Greedy algorithms

Complete search

Mathematics

Constructive algorithms


Solutions:
from sys import stdin
import math
from collections import deque
from heapq import heapify, heappop, heappush
from bisect import bisect_left, bisect_right
input = stdin.readline

def log(n, m):
	(res, val) = (0, 1)
	while True:
		if n == val:
			return res
		elif n > val:
			return res - 1
		res += 1
		val *= m

def ceil(m, n):
	val = m // n
	if m % n != 0:
		return val + 1
	return val
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	(val, rem) = (n // m, n % m)
	arr = [val] * m
	for i in range(m - 1, -1, -1):
		if rem == 0:
			break
		arr[i] += 1
		rem -= 1
	(value, newvalue) = (1, 1)
	for _ in range(k):
		value = newvalue
		for i in range(m):
			change = arr[i] == val
			j = arr[i]
			print(j, end=' ')
			(c, res) = (0, [])
			while c < j:
				res.append(str(value))
				value = value + 1
				if value == n + 1:
					value = 1
				if change:
					newvalue = value
				c += 1
			print(' '.join(res))
	print()


import io, os
import sys
from sys import stdin
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, namedtuple
from heapq import heappush, heappop
from math import gcd, ceil, floor, factorial, sqrt
from itertools import combinations, permutations
input = sys.stdin.buffer.readline

def work():
	ans = 0
	return

def main():
	test = int(input())
	for idt in range(test):
		(n, m, k) = map(int, input().split())
		(big_p, small_p) = ((n + m - 1) // m, n // m)
		big_num = n - m * big_p + m
		small_num = m - big_num
		h = []
		b = defaultdict(int)
		for i in range(1, n + 1):
			heappush(h, [0, i])
			b[i] = 0
		for _ in range(k):
			small = []
			big = []
			for _ in range(big_p * big_num):
				(_, pid) = heappop(h)
				big.append(pid)
				b[pid] += 1
			for _ in range(small_p * small_num):
				(_, pid) = heappop(h)
				small.append(pid)
			for i in range(0, len(small), small_p):
				print(small_p, end=' ')
				for j in range(i, i + small_p):
					print(small[j], end=' ')
				print()
			for i in range(0, len(big), big_p):
				print(big_p, end=' ')
				for j in range(i, i + big_p):
					print(big[j], end=' ')
				print()
			for i in range(1, n + 1):
				heappush(h, [b[i], i])
		print()
	return

def main_jly():
	test = int(input())
	for idt in range(test):
		(n, m, k) = map(int, input().split())
		for i in range(k):
			idx = n % m * ((n + m - 1) // m) * i % n
			for j in range(n % m):
				print((n + m - 1) // m, end=' ')
				for l in range((n + m - 1) // m):
					print(idx + 1, end=' ')
					idx = (idx + 1) % n
				print()
			for j in range(m - n % m):
				print(n // m, end=' ')
				for l in range(n // m):
					print(idx + 1, end=' ')
					idx = (idx + 1) % n
				print()
		print()
main_jly()


import sys
input = sys.stdin.readline
t = int(input())
ans = []
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if n % m == 0:
		c = n // m
		ans0 = []
		for _ in range(k):
			for i in range(m):
				ans0.append(' '.join(map(str, [c] + [j + i * c + 1 for j in range(c)])))
		ans.append('\n'.join(ans0))
		continue
	x = [n // m + min(n % m, 1)] * m
	s = sum(x)
	u = 0
	for i in range(s - n):
		x[i] -= 1
		u += x[i]
	c = u * k
	y = [set() for _ in range(k)]
	z = [c // n + min(c % n, 1)] * n
	s = sum(z)
	for i in range(s - c):
		z[i] -= 1
	j = 0
	for i in range(n):
		for _ in range(z[i]):
			y[j].add(i + 1)
			j += 1
			j %= k
	ans0 = []
	for i in range(k):
		a = y[i]
		b = set()
		for j in range(1, n + 1):
			if not j in a:
				b.add(j)
		a = list(a)
		b = list(b)
		for j in x:
			ans00 = [j]
			if j == x[0]:
				for _ in range(j):
					ans00.append(a.pop())
			else:
				for _ in range(j):
					ans00.append(b.pop())
			ans0.append(' '.join(map(str, ans00)))
	ans.append('\n'.join(ans0))
sys.stdout.write('\n\n'.join(ans))


from __future__ import division, print_function
import math
import sys
import os
from io import BytesIO, IOBase
from typing import DefaultDict
from collections import deque, Counter, OrderedDict, defaultdict
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')

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))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return int(input())

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

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

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	(n, m, k) = invr()
	v1 = n // m
	z = v1 * m
	ex = n - z
	d = defaultdict(lambda : [0, 0])
	strt = 1
	extra = []
	nonex = []
	for j in range(k):
		dct = defaultdict(lambda : 1)
		ex2 = []
		for j2 in range(ex):
			for j3 in range(v1 + 1):
				dct[strt] = 0
				ex2.append(strt)
				d[strt][0] += 1
				strt = (strt + 1) % n
				if strt == 0:
					strt = n
		ex3 = []
		for i in range(1, n + 1):
			if dct[i] == 1:
				ex3.append(i)
		for i in range(len(ex2)):
			if i % (v1 + 1) == 0:
				print()
				print(v1 + 1, end=' ')
			print(ex2[i], end=' ')
		for i in range(len(ex3)):
			if i % v1 == 0:
				print()
				print(v1, end=' ')
			print(ex3[i], end=' ')
	print()


import os
import sys
from io import BytesIO, IOBase
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')
from math import ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
from collections import deque
for _ in range(int(input()) if True else 1):
	(n, m, k) = map(int, input().split())
	if n % m == 0:
		for __ in range(k):
			cur = 1
			for i in range(m):
				ans = [n // m]
				for j in range(n // m):
					ans += [cur]
					cur += 1
				print(*ans)
		continue
	high = (n + m - 1) // m * (n % m)
	low = n - high
	big = (n + m - 1) // m
	smol = big - 1
	a = deque(list(range(1, n + 1)))
	for __ in range(k):
		p = 0
		for i in range(m):
			ans = []
			if i < n % m:
				ans += [big]
				for j in range(big):
					ans += [a.popleft()]
					a += [ans[-1]]
			else:
				ans += [smol]
				for j in range(smol):
					ans += [a[p]]
					p += 1
			print(*ans)
	print()


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	(n, m, k) = [int(i) for i in input().split()]
	mod = n % m
	small = n // m
	big = (n + m - 1) // m
	y = big * mod
	a = [[0] * n for i in range(k)]
	cnt = 0
	for kk in range(k):
		for i in range(y):
			a[kk][cnt % n] = 1
			cnt += 1
	ans = []
	for j in range(k):
		cb = []
		cs = []
		for i in range(len(a[j])):
			if a[j][i] == 0:
				cs.append(i + 1)
			else:
				cb.append(i + 1)
			if len(cs) == small:
				ans.append(cs[:])
				cs = []
			if len(cb) == big:
				ans.append(cb[:])
				cb = []
	for i in ans:
		print(len(i), *i)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	groups = []
	arr = [i + 1 for i in range(n)]
	z = 0
	if n % m != 0:
		larger = n // m + 1
		while n % m != 0:
			groups.append(larger)
			n -= larger
			m -= 1
			z += larger
	a = n // m
	for _ in range(m):
		groups.append(a)
	while k:
		curr = 0
		for i in groups:
			print(i, end=' ')
			j = i
			while j:
				print(arr[curr], end=' ')
				curr += 1
				j -= 1
			print()
		arr = arr[z:] + arr[:z]
		k -= 1
	print()


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	for _ in range(1, ii() + 1):
		(n, m, k) = mi()
		r_up = (n + m - 1) // m
		r_down = n // m
		big_group = n % m * r_up
		small_group = n - big_group
		big_group_start = 0
		for i in range(k):
			cur = big_group_start
			for j in range(big_group):
				if j % r_up == 0:
					if j:
						print()
					print(r_up, end=' ')
				print(cur + 1, end=' ')
				cur += 1
				cur %= n
			if big_group:
				print()
			for j in range(small_group):
				if j % r_down == 0:
					if j:
						print()
					print(r_down, end=' ')
				print(cur + 1, end=' ')
				cur += 1
				cur %= n
			if small_group:
				print()
			big_group_start += big_group
			big_group_start %= n
		print()
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


import sys
I = lambda : [*map(int, sys.stdin.readline().split())]
(t,) = I()
for _ in range(t):
	(n, m, k) = I()
	players = [i + 1 for i in range(n)]
	big = n % m
	sml = m - big
	for i in range(k):
		start = n * i // k
		ind = start
		for j in range(big):
			out = [str(n // m + 1)]
			for l in range(n // m + 1):
				out.append(str(players[ind]))
				ind = (ind + 1) % n
			print(' '.join(out))
		for j in range(sml):
			out = [str(n // m)]
			for l in range(n // m):
				out.append(str(players[ind]))
				ind = (ind + 1) % n
			print(' '.join(out))


from math import inf, gcd, log, log2, floor, ceil, sqrt
from collections import Counter, defaultdict
DIRS = [[1, 0], [0, 1], [0, -1], [-1, 0]]
MOD = 10 ** 9 + 7

def solve(n, m, k):
	start_i = 0
	people = [x for x in range(1, n + 1)]
	ans = []
	big = ceil(n / m)
	small = floor(n / m)
	big_groups = n % m
	small_groups = (n - big_groups * big) // small
	for j in range(k):
		i = start_i
		for group in range(big_groups):
			tmp = [n // m + 1]
			for _ in range(n // m + 1):
				tmp.append(people[i])
				i += 1
				if i == len(people):
					i = 0
			start_i = i
			ans.append(tmp)
		for group in range(small_groups):
			tmp = [n // m]
			for _ in range(n // m):
				tmp.append(people[i])
				i += 1
				if i == len(people):
					i = 0
			ans.append(tmp)
	return ans
t = int(input())
for tc in range(t):
	(n, m, k) = [int(x) for x in input().split(' ')]
	for x in solve(n, m, k):
		print(*x)
	if tc != t - 1:
		print()


import sys

def input():
	return sys.stdin.readline().rstrip()
DXY = [(0, -1), (1, 0), (0, 1), (-1, 0)]
mod = 998244353
inf = 1 << 64

def slv():
	(n, m, k) = map(int, input().split())
	if n % m == 0:
		for i in range(k):
			persons = [i + 1 for i in range(n)]
			for _ in range(m):
				tmp = []
				for j in range(n // m):
					tmp.append(persons.pop())
				print(len(tmp), *tmp)
	else:
		number = 1
		md = n % m
		for i in range(k):
			new_number = -1
			tmp = [[] for _ in range(m)]
			for j in range(m):
				if j < md:
					for _ in range(n // m + 1):
						tmp[j].append(number)
						number += 1
						if number > n:
							number -= n
						new_number = number
				else:
					for _ in range(n // m):
						tmp[j].append(number)
						number += 1
						if number > n:
							number -= n
			for j in range(m):
				print(len(tmp[j]), *tmp[j])
			number = new_number
	print('')
	return

def main():
	t = int(input())
	for i in range(t):
		slv()
	return 0
main()


import sys
from bisect import bisect_left as lb
from bisect import bisect_right as rb
from collections import deque
from queue import PriorityQueue as pq
from math import gcd
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
lii = lambda : list(map(int, list(ip())))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
mod = 10 ** 9 + 7
mod1 = 998244353
for _ in range(ii()):
	(n, m, k) = il()
	a = [i for i in range(1, n + 1)]
	x = n // m
	y = -(-n // m)
	t1 = n % m
	if t1 == 0:
		for nm in range(k):
			print(x, end=' ')
			for i in range(n):
				if i % x == 0 and i != 0:
					print()
					print(x, end=' ')
				print(a[i], end=' ')
			print()
		print()
		continue
	i1 = 0
	j1 = y * t1
	for i in range(k):
		mn = 0
		for j in range(t1):
			print(y, end=' ')
			for nm in range(y):
				print(a[mn], end=' ')
				mn += 1
			print()
		for j in range(m - t1):
			print(x, end=' ')
			for nm in range(x):
				print(a[mn], end=' ')
				mn += 1
			print()
		for j in range(n - x * (m - t1)):
			(a[i1], a[j1]) = (a[j1], a[i1])
			i1 += 1
			j1 += 1
			if i1 >= y * t1:
				i1 = 0
			if j1 >= n:
				j1 = y * t1
	print()


import io, os
from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(n, m, k) = map(int, input().split())
	size = n // m
	Rounded_up = n % m
	Rounded_down = (n - Rounded_up * (size + 1)) // size
	cnt = 1
	for i in range(k):
		for j in range(Rounded_up):
			print(size + 1, end=' ')
			for l in range(size + 1):
				print(cnt, end=' ')
				cnt += 1
				cnt %= n
				if cnt == 0:
					cnt = n
			print()
		for j in range(Rounded_down):
			print(size, end=' ')
			for l in range(size):
				print(cnt, end=' ')
				cnt += 1
				cnt %= n
				if cnt == 0:
					cnt = n
			print()
		cnt += Rounded_up * (size + 1)
		cnt %= n
		if cnt == 0:
			cnt = n
	print()


import math
from heapq import heapify, heappush, heappop

def solve(n, m, k):
	if n % m == 0:
		nm = n // m
		players = [str(i + 1) for i in range(n)]
		for game in range(k):
			cur = 0
			for i in range(m):
				l = [str(nm)] + players[cur:cur + nm]
				print(' '.join(l))
				cur += nm
		return
	else:
		nm = n // m + 1 if n % m != 0 else n // m
		shift = n % m * nm
		big_table = n % m
		players = [str(i + 1) for i in range(n)]
		for game in range(k):
			cur = 0
			for i in range(big_table):
				l = [str(nm)] + players[cur:cur + nm]
				print(' '.join(l))
				cur += nm
			small_table = m - big_table
			for i in range(small_table):
				l = [str(nm - 1)] + players[cur:cur + nm - 1]
				print(' '.join(l))
				cur += nm - 1
			players_new = players[:]
			for (i, p) in enumerate(players):
				players_new[(i + shift) % n] = p
			players = players_new
import os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input().decode().strip())
for t in range(T):
	(n, m, k) = [int(x) for x in input().decode().strip().split(' ')]
	solve(n, m, k)
	print('', flush=True)


import sys
import math
from collections import deque, Counter
from sys import stdin
int1 = lambda x: int(x) - 1
stinput = lambda : stdin.readline()[:-1]
ii = lambda : int(stinput())
mi = lambda : map(int, stdin.readline().split())
li = lambda : list(mi())
mi1 = lambda : map(int1, stdin.readline().split())
li1 = lambda : list(mi1())
mis = lambda : map(str, stdin.readline().split())
lis = lambda : list(mis())
from collections import defaultdict
import heapq
mod = 10 ** 9 + 7
Mod = 998244353
INF = 10 ** 18
ans = 0
print1 = lambda x: print(*[i + 1 for i in x])
t = ii()
for _ in range(t):
	(n, m, k) = mi()
	a = n % m
	if a == 0:
		a = m
	b = m - a
	c = (n + m - 1) // m
	tmp = 0
	for i in range(k):
		for j in range(a):
			ans = [c - 1]
			for x in range(c):
				ans.append(tmp)
				tmp += 1
				tmp %= n
			print1(ans)
		nx = tmp
		for j in range(b):
			ans = [c - 2]
			for x in range(c - 1):
				ans.append(nx)
				nx += 1
				nx %= n
			print1(ans)
	print()


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	st = 1
	for i in range(k):
		(tt, rem, nxt) = (n // m, n % m, st)
		for j in range(m):
			print(str(tt + 1 if rem else tt) + ' ')
			for k in range(tt):
				print(str(st) + ' ')
				st += 1
				if st == n + 1:
					st = 1
			if rem:
				rem -= 1
				print(str(st) + ' ')
				st += 1
				if st == n + 1:
					st = 1
				if rem == 0:
					nxt = st
			print('\n')
		st = nxt
	print('\n')


import sys
import bisect
from bisect import bisect_left as lb
from bisect import bisect_right as rb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
sys.setrecursionlimit(3 * 10 ** 5)
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs2(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0
a = []
(n, k) = (0, 0)
b = []
vis = []
tot = 0
time = []
time1 = []
adj = []
mx = -1
eps = 1e-07
x = 0
pref = []
lvl = []
gp = []
ans = []
f = 0
w = []
fact = [1, 1]
inv = [1, 1]
for i in range(2, 10 ** 3 + 10):
	fact.append(fact[-1] * i % mod)
	inv.append(pow(fact[-1], mod - 2, mod))

def ncr(n, r):
	global fact, inv
	if r == 0:
		return 1
	ans = fact[n] * inv[r] * inv[n - r]
	ans %= mod
	return ans

def hnbhai(tc):
	(n, m, k) = sd()
	cl = -(-n // m)
	flr = n // m
	extra = n % m
	if extra == 0:
		for i in range(k):
			for j in range(m):
				print(flr, end=' ')
				for l in range(j * flr, (j + 1) * flr):
					print(l + 1, end=' ')
				print()
		print()
		return
	ans = [i + 1 for i in range(n)]
	strt = 0
	end = cl * extra
	for i in range(k):
		for j in range(extra):
			print(cl, end=' ')
			for l in range(j * cl, (j + 1) * cl):
				print(ans[l], end=' ')
			print()
		ee = extra * cl
		for j in range(m - extra):
			print(flr, end=' ')
			for l in range(ee, ee + flr):
				print(ans[l], end=' ')
			print()
			ee += flr
		for j in range(n - flr * (m - extra)):
			(ans[strt], ans[end]) = (ans[end], ans[strt])
			strt += 1
			end += 1
			if strt >= cl * extra:
				strt = 0
			if end >= n:
				end = cl * extra
for _ in range(sb()):
	hnbhai(_ + 1)


t = int(input())
for test in range(t):
	(n, m, k) = list(map(int, input().split()))
	cnt = (n + m - 1) // m * (n % m)
	now = 1
	for i in range(k):
		for j in range(n % m):
			print((n + m - 1) // m, end=' ')
			for x in range((n + m - 1) // m):
				print(now, end=' ')
				now += 1
				if now == n + 1:
					now = 1
			print()
		tmp = now
		for j in range(m - n % m):
			print(n // m, end=' ')
			for x in range(n // m):
				print(now, end=' ')
				now += 1
				if now == n + 1:
					now = 1
		now = tmp
		print()


def solve():
	(n, m, k) = readIntArr()
	smallPeople = n // m
	largePeople = smallPeople + 1
	smallTable = largePeople * m - n
	largeTable = m - smallTable
	ans = []
	largeIdx = 0
	for roundd in range(k):
		for _ in range(largeTable):
			arr = [largePeople]
			for __ in range(largePeople):
				arr.append(largeIdx + 1)
				largeIdx += 1
				largeIdx %= n
			ans.append(arr)
		smallIdx = largeIdx
		for _ in range(smallTable):
			arr = [smallPeople]
			for __ in range(smallPeople):
				arr.append(smallIdx + 1)
				smallIdx += 1
				smallIdx %= n
			ans.append(arr)
		ans.append([''])
	multiLineArrayOfArraysPrint(ans)

def main():
	t = int(input())
	for _ in range(t):
		solve()
		print()
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(a, b, c):
	print('? {} {} {}'.format(a, b, c))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ansArr):
	print('! {}'.format(' '.join([str(x) for x in ansArr])))
	sys.stdout.flush()
inf = float('inf')
from math import gcd, floor, ceil
import math
for _abc in range(1):
	main()


from collections import defaultdict
from heapq import heappush, heappop

def main():
	test = int(input())
	for _ in range(test):
		(n, m, k) = map(int, input().split())
		(big_p, small_p) = ((n + m - 1) // m, n // m)
		big_num = n - m * big_p + m
		small_num = m - big_num
		h = []
		b = defaultdict(int)
		for i in range(1, n + 1):
			heappush(h, [0, i])
			b[i] = 0
		for _ in range(k):
			small = []
			big = []
			for _ in range(big_p * big_num):
				(_, pid) = heappop(h)
				big.append(pid)
				b[pid] += 1
			for _ in range(small_p * small_num):
				(_, pid) = heappop(h)
				small.append(pid)
			for i in range(0, len(small), small_p):
				print(small_p, end=' ')
				for j in range(i, i + small_p):
					print(small[j], end=' ')
				print()
			for i in range(0, len(big), big_p):
				print(big_p, end=' ')
				for j in range(i, i + big_p):
					print(big[j], end=' ')
				print()
			for i in range(1, n + 1):
				heappush(h, [b[i], i])
		print()
	return
main()


import math, sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
mod1 = 1000000007
mod2 = 998244353
for _ in range(I()):
	(n, m, k) = M()
	a = math.ceil(n / m)
	b = math.floor(n / m)
	c = n % m * a
	cur = 0
	for i in range(k):
		s = set()
		for j in range(n % m):
			l = [a]
			for t in range(a):
				l.append(cur % n + 1)
				cur += 1
				s.add(l[-1])
			print(*l)
		p = 1
		for j in range(m - n % m):
			l = [b]
			t = 0
			while t < b:
				if p not in s:
					l.append(p)
					t += 1
				p += 1
			print(*l)
	print()


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

def main(t):
	(n, m, k) = map(int, input().split())
	base = n // m
	for i in range(k):
		frontnum = (n - base * m) * (base + 1) * i
		rearnum = (n - base * m) * (base + 1) * (i + 1)
		visited = [False] * n
		groups = [[] for _ in range(m)]
		for j in range(frontnum, rearnum):
			visited[j % n] = True
			groups[(j - frontnum) // (base + 1)].append(j % n + 1)
		index = 0
		for j in range(n):
			if visited[j]:
				continue
			groups[n - base * m + index // base].append(j + 1)
			index += 1
		for g in groups:
			temp = [len(g)] + g
			print(*temp)
	print(' ')
T = int(input())
t = 1
while t <= T:
	main(t)
	t += 1


import sys

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

def print_table(nums):
	print(f"{len(nums)} {' '.join([str(x) for x in nums])}")
t = int(read_line())
for _ in range(t):
	(n, m, k) = tuple([int(x) for x in read_line().split()])
	big_tables_starting_num = 0
	big_tables_count = n % m
	big_tables_size = 1 + n // m
	small_tables_count = m - n % m
	small_tables_size = n // m
	people_at_big_tables = big_tables_size * big_tables_count
	big_table_nums = [-1] * big_tables_size
	small_table_nums = [-1] * small_tables_size
	for _ in range(k):
		i = 0
		for bt in range(big_tables_count):
			for x in range(1 + n // m):
				big_table_nums[x] = (big_tables_starting_num + i) % n + 1
				i += 1
			print_table(big_table_nums)
		for st in range(small_tables_count):
			for x in range(n // m):
				small_table_nums[x] = (big_tables_starting_num + i) % n + 1
				i += 1
			print_table(small_table_nums)
		big_tables_starting_num = (big_tables_starting_num + people_at_big_tables) % n
	print()


t = int(input())
for case in range(t):
	(n, m, k) = tuple(map(int, input().split()))
	p = n // m
	q = p + 1
	r = n % m
	nouveau_indice = 1
	for i in range(k):
		indice = nouveau_indice
		for j in range(m):
			if j < r:
				s = str(q)
				for u in range(q):
					s += ' ' + str(indice)
					indice += 1
					if indice == n + 1:
						indice = 1
				print(s)
			else:
				if j == r:
					nouveau_indice = indice
				s = str(p)
				for u in range(p):
					s += ' ' + str(indice)
					indice += 1
					if indice == n + 1:
						indice = 1
				print(s)
	print('')


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))

class OrderedList(SortedList):

	def __init__(self, arg):
		super().__init__(arg)

	def rangeCountByValue(self, leftVal, rightVal):
		leftCummulative = self.bisect_left(leftVal)
		rightCummulative = self.bisect_left(rightVal + 1)
		return rightCummulative - leftCummulative

def solve():
	(n, m, k) = readIntArr()
	smallPeople = n // m
	largePeople = smallPeople + 1
	smallTable = largePeople * m - n
	largeTable = m - smallTable
	playerCnts = SortedList([(0, i) for i in range(1, n + 1)])
	ans = []
	for roundd in range(k):
		playerCnts2 = SortedList()
		for _ in range(largeTable):
			sz = largePeople
			arr = [sz]
			for __ in range(sz):
				(b, player) = playerCnts.pop(0)
				arr.append(player)
				playerCnts2.add((b + 1, player))
			ans.append(arr)
		for _ in range(smallTable):
			sz = smallPeople
			arr = [sz]
			for __ in range(sz):
				(b, player) = playerCnts.pop(-1)
				arr.append(player)
				playerCnts2.add((b, player))
			ans.append(arr)
		playerCnts = playerCnts2
		ans.append([''])
	multiLineArrayOfArraysPrint(ans)

def main():
	t = int(input())
	for _ in range(t):
		solve()
		print()
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(a, b, c):
	print('? {} {} {}'.format(a, b, c))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ansArr):
	print('! {}'.format(' '.join([str(x) for x in ansArr])))
	sys.stdout.flush()
inf = float('inf')
from math import gcd, floor, ceil
import math
for _abc in range(1):
	main()


import math
t = int(input())
for _ in range(t):
	(players_no, tables_no, games_no) = (int(el) for el in input().split())
	small_table_size = players_no // tables_no
	big_table_size = math.ceil(players_no / tables_no)
	big_table_no = players_no % tables_no
	small_tables_no = tables_no - big_table_no
	first_small = 0
	for game_no in range(games_no):
		for i in range(big_table_no):
			print(big_table_size, end=' ')
			for j in range(big_table_size):
				print((first_small + j) % players_no + 1, end='\n' if j == big_table_size - 1 else ' ')
			first_small += big_table_size % players_no
		fill_player_no = first_small
		for i in range(small_tables_no):
			print(small_table_size, end=' ')
			for j in range(small_table_size):
				print((fill_player_no + j) % players_no + 1, end='\n' if j == small_table_size - 1 else ' ')
			fill_player_no += small_table_size % players_no
	print('')


t = int(input())
for test in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	mx = n // m + 1
	table = [[0] * mx in range(k)]
	lastUnfair = 1
	for p in range(k):
		curply = lastUnfair
		for table in range(m - (m - n % m)):
			print(mx, end=' ')
			plys = 0
			while plys < mx:
				if curply > n:
					curply = 1
				print(curply, end=' ')
				plys += 1
				curply += 1
			print()
		lastUnfair = curply
		for table in range(m - n % m):
			print(mx - 1, end=' ')
			plys = 0
			while plys < mx - 1:
				if curply > n:
					curply = 1
				print(curply, end=' ')
				plys += 1
				curply += 1
			print()