Read problems statements in mandarin chinese, russian and vietnamese as well. 

This year CodeChef is organizing the SnackUp cooking contest. The favorite to win is of course our beautiful Chef Ada.

There are n judges in the contest, and for simplicity let's enumerate judges from 1 to n. 

Ada has an uncountable repertoire of delicious recipes, but for the contest she choose only n of them. Let's also enumerate the recipes from 1 to n.

Ada is going to show off her cooking skills in many rounds, and we are going to help her organizing them! One round is structured as follows:
We will choose k distinct recipes and Ada will prepare two identical dishes for each of them.
We will choose k distinct judges for the round.
We will send k invitation letters (one for each of the chosen judges). Each letter must contain the number of the judge, and two distinct integers denoting the ids of the recipes that he is going to taste. 
Two different judges can taste the same recipe, but it must be from different dishes. 
Ada does not like to waste food, so the letters must be designed in such a way that every prepared dish is tasted.

You can arbitrarily decide the number of rounds and the number of invited judges in each round, but as a rule of the contest at the end of all rounds each judge must have tasted every recipe exactly twice.

------ Input ------ 

The first line of input contains one number T, the number of test cases.
Each test case consist of one line containing an integer n, the number of judges.

------ Output ------ 

For each testcase, in the first line, print r the number of rounds, then describe each round as follows.

In the first line of each round, print k, the number of invited judges.
In the next k lines, print the invitation letters as three space separated integers: j, x, y denoting the id of the judge, and the ids of the recipe that he is going to taste. Note that x should not be equal to y.

------ Constraints ------ 

1 ≤ T ≤ 100
2 ≤ n ≤ 100

----- Sample Input 1 ------ 
1
2
----- Sample Output 1 ------ 
2
2
1 1 2
2 1 2
2
1 1 2
2 1 2

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Constructive algorithms

Ad-hoc


Solutions:
def soln(n):
	arr = [(i, i + 1) for i in range(1, n)]
	arr.append((1, n))
	print(n)
	for i in range(n):
		print(n)
		for j in range(n):
			print(j + 1, *arr[(i + j) % n])
for _ in range(int(input())):
	n = int(input())
	soln(n)


for i in range(int(input())):
	n = int(input())
	k = range(1, n + 1)
	print(n)
	for i in range(1, n + 1):
		print(n)
		for j in range(1, n + 1):
			print(j, k[(i + j - 1) % n], k[(i + j) % n])


from collections import deque

def solve():
	n = int(input())
	q = deque()
	for i in range(n):
		q.append((i + 1, (i + 1) % n + 1))
	print(n)
	for _ in range(n):
		print(n)
		for (i, (x, y)) in enumerate(q, start=1):
			print(i, x, y)
		q.append(q.popleft())
for _ in range(int(input())):
	solve()


tc = int(input())
for _ in range(tc):
	n = int(input())
	N = range(1, n + 1)
	print(n)
	for i in range(1, n + 1):
		print(n)
		for j in range(1, n + 1):
			print(j, N[(i + j - 1) % n], N[(i + j) % n])


testcase = int(input())
for _ in range(testcase):
	numberOFJudges = int(input())
	numberOFRounds = numberOFJudges
	print(numberOFRounds)
	IDofRecipe_1 = 1
	IDofRecipe_2 = 2
	for i in range(numberOFRounds - 1):
		print(numberOFJudges)
		for IDofJudges in range(numberOFJudges):
			print(IDofJudges + 1, IDofRecipe_1, IDofRecipe_2)
		IDofRecipe_1 = IDofRecipe_1 + 1
		IDofRecipe_2 = IDofRecipe_2 + 1
	print(numberOFJudges)
	for IDofJudges in range(numberOFJudges):
		print(IDofJudges + 1, 1, numberOFJudges)


for _ in range(int(input())):
	n = int(input())
	print(n)
	x = 1
	y = 2
	for i in range(n - 1):
		print(n)
		for j in range(n):
			print(j + 1, x, y)
		x += 1
		y += 1
	print(n)
	for i in range(n):
		print(i + 1, 1, n)


def solve():
	print(n)
	(x, y) = (1, 2)
	for r in range(n - 1):
		print(n)
		for j in range(1, n + 1):
			print(j, x, y)
		x += 1
		y += 1
	print(n)
	for j in range(1, n + 1):
		print(j, 1, n)
t = int(input())
for _ in range(t):
	n = int(input())
	solve()


for _ in range(int(input())):
	n = int(input())
	print(n)
	s = range(1, n + 1)
	for i in range(1, n + 1):
		print(n)
		for j in range(1, n + 1):
			print(j, s[(j + i - 1) % n], s[(j + i) % n])


from sys import stdin, stdout
import math
from collections import Counter
import functools
import time
import bisect

def tr():
	return range(int(line()))

def sm():
	return map(int, line().split())

def ln():
	return list(sm())

def nl():
	return int(line())

def ssm():
	return map(str, line().split())

def line():
	return stdin.readline().rstrip()

def b(x):
	return bin(x).replace('0b', '')

def o(x):
	if type(x) != type(''):
		x = str(x)
	stdout.write(x + '\n')

def osp(x):
	if type(x) != type(''):
		x = str(x)
	stdout.write(x + ' ')

def ol(x):
	stdout.write(' '.join(map(str, x)))

def wline():
	return stdin.read().split()

def main():
	for _ in tr():
		n = nl()
		print(n)
		for i in range(0, n):
			dish_one = i % n + 1
			dish_two = (i + 1) % n + 1
			print(n)
			for j in range(0, n):
				print(j + 1, dish_one, dish_two)
main()


t = int(input())
for i in range(t):
	n = int(input())
	s = range(1, n + 1)
	print(n)
	for j in range(1, n + 1):
		print(n)
		for k in range(1, n + 1):
			print(k, s[(j + k - 1) % n], s[(j + k) % n])


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(1, n):
		l.append((i, i + 1))
	l.append((n, 1))
	print(n)
	for i in range(n):
		print(n)
		j = 1
		while j <= n:
			print(j, l[j - 1][0], l[j - 1][1])
			j += 1
		l = l[1:] + [l[0]]


t = int(input())
for i in range(t):
	n = int(input())
	r = n
	print(r)
	for k in range(n):
		no_judges = n
		print(no_judges)
		for j in range(n):
			r1 = (k + j) % n + 1
			r2 = (k + j + 1) % n + 1
			print(j + 1, ' ', r1, ' ', r2)


t = int(input())
for _ in range(t):
	n = int(input())
	print(n)
	for i in range(1, n + 1):
		y = 1
		print(n)
		for j in range(i, n + 1):
			if j == n:
				print(y, j, 1)
				y += 1
			else:
				print(y, j, j + 1)
				y += 1
		x = 1
		while x <= i - 1:
			print(y, x, x + 1)
			x += 1
			y += 1


for _ in range(int(input())):
	n = int(input())
	print(n)
	for i in range(n):
		item1 = i % n + 1
		item2 = (i + 1) % n + 1
		print(n)
		for j in range(n):
			print(j + 1, item1, item2)


for i in range(int(input())):
	n = int(input())
	c = 0
	print(n)
	for j in range(n):
		c += 1
		print(n)
		for i in range(n):
			print(i + 1, end=' ')
			if c > n:
				c = 1
			print(c, end=' ')
			c += 1
			if c > n:
				c = 1
			print(c)


for _ in range(int(input())):
	n = int(input())
	count = 0
	print(n)
	for j in range(n):
		count += 1
		print(n)
		for i in range(n):
			print(i + 1, end=' ')
			if count > n:
				count = 1
			print(count, end=' ')
			count += 1
			if count > n:
				count = 1
			print(count)


for _ in range(int(input())):
	n = int(input())
	x = 1
	y = 2
	print(n)
	print(n)
	x = 1
	y = 2
	round1 = 1
	judge = 1
	while round1 <= n * (n + 1):
		if judge % (n + 1) == 0 and round1 != n * (n + 1):
			print(n)
			judge = 1
			x = x + 1
			y = y + 1
		elif round1 != n * (n + 1):
			if x > n:
				x = 1
			if y > n:
				y = 1
			print(judge, x, y)
			judge += 1
			x = x + 1
			y = y + 1
			if x > n:
				x = 1
			if y > n:
				y = 1
		round1 += 1


for _ in range(int(input())):
	n = int(input())
	print(n)
	for r in range(n):
		print(n)
		for i in range(n):
			print(i + 1, (i + r) % n + 1, (i + r + 1) % n + 1)


for _ in range(int(input())):
	n = int(input())
	print(n)
	for r in range(n):
		print(n)
		for j in range(n):
			print(j + 1, (j + r) % n + 1, (j + r + 1) % n + 1)


for _ in range(int(input().strip())):
	n = int(input().strip())
	print(n)
	for i in range(n):
		print(n)
		for k in range(n):
			print(k + 1, i + k + 1 if i + k + 1 <= n else i + k + 1 - n, i + k + 2 if i + k + 2 <= n else i + k + 2 - n)


for _ in range(int(input())):
	N = int(input())
	print(N)
	for i in range(1, N + 1):
		print(N)
		k = 1
		for j in range(i, i + N):
			y = j % (N + i)
			if y > N:
				y -= N
			z = y
			if y < N:
				z += 1
			else:
				z = 1
			print(k, y, z)
			k += 1


def snack_up(test_integer):
	count = 0
	print(test_integer)
	for _ in range(test_integer):
		count += 1
		print(test_integer)
		for i in range(test_integer):
			print(i + 1, end=' ')
			if count > test_integer:
				count = 1
			print(count, end=' ')
			count += 1
			if count > test_integer:
				count = 1
			print(count)
for _ in range(int(input())):
	NUMBER_JUDGE = int(input())
	snack_up(NUMBER_JUDGE)


for i in range(int(input())):
	n = int(input())
	print(n)
	for k in range(n):
		print(n)
		for l in range(n):
			print(str(l + 1) + ' ' + str((k + l) % n + 1) + ' ' + str((k + l + 1) % n + 1))


test_cases = int(input())
while test_cases > 0:
	n = int(input())
	print(n)
	counter = 0
	for i in range(n):
		print(n)
		counter = i
		for j in range(1, n + 1):
			counter += 1
			if (counter + 1) % (n + 1) == 0:
				print(j, counter, 1)
				counter = 0
			else:
				print(j, counter, counter + 1)
	test_cases -= 1


for t in range(int(input())):
	n = int(input())
	print(n)
	(f, s) = (0, 0)
	for i in range(n):
		s = i + 1
		print(n)
		for j in range(n):
			f = s
			if f > n:
				f = 1
			s = f + 1
			if s > n:
				s = 1
			print(j + 1, f, s)


def rotate(arr):
	temp = arr[-1]
	new_temp1 = arr[1]
	for i in range(1, len(arr), 2):
		if i + 2 <= len(arr):
			new_temp2 = arr[i + 2]
			arr[i + 2] = new_temp1
			new_temp1 = new_temp2
	arr[1] = temp
for t in range(int(input())):
	n = int(input())
	arr = []
	print(n)
	for i in range(n):
		arr.append(i + 1)
		arr.append('j' + str(i + 1))
	for k in range(n):
		print(n)
		for i in range(n):
			j = i + 1
			index = arr.index('j' + str(j))
			if index + 1 < len(arr):
				print(i + 1, arr[index - 1], arr[index + 1])
			else:
				print(i + 1, arr[0], arr[index - 1])
		rotate(arr)


for t in range(int(input())):
	nj = int(input())
	print(nj)
	a = [i % nj + 1 for i in range(nj)]
	for j in range(nj):
		print(nj)
		c = j
		for k in range(nj):
			print(k + 1, a[c % nj], a[(c + 1) % nj])
			c += 1


for _ in range(int(input())):
	n = int(input())
	print(n)
	for i in range(n):
		print(n)
		for j in range(n):
			print(j + 1, (j + i) % n + 1, (j + i + 1) % n + 1, sep=' ')


t = int(input())
while t:
	n = int(input())
	print(n)
	for i in range(n):
		print(n)
		for j in range(n):
			to = (i + j) % n + 1
			if to == n:
				print(j + 1, to, 1)
			else:
				print(j + 1, to, to + 1)
	t -= 1


T = int(input())
for eachCase in range(T):
	n = int(input())
	print(n)
	(x, y) = (1, 2)
	for i in range(n):
		print(n)
		for j in range(1, n + 1):
			print(j, x, y)
			x = y
			if y == n:
				y = 0
			y += 1
		x = y
		if y == n:
			y = 0
		y += 1


for i in range(int(input())):
	n = int(input())
	print(n)
	for i in range(n):
		print(n)
		start = i
		for j in range(1, n + 1):
			print(j, start % n + 1, end=' ')
			start += 1
			print(start % n + 1)


for x in range(int(input())):
	n = int(input())
	l = [i for i in range(1, n + 1)]
	l = l + l
	l.append(1)
	r = n
	print(r)
	for i in range(r):
		print(n)
		for j in range(n):
			print(str(j + 1) + ' ' + str(l[j + i]) + ' ' + str(l[j + i + 1]))


t = int(input())
while t > 0:
	n = int(input())
	print(n)
	for j in range(1, n + 1):
		print(n)
		c = j
		for i in range(1, n + 1):
			if c == n:
				print(i, c, 1)
				c = 1
			else:
				print(i, c, c + 1)
				c += 1
	t -= 1


for t in range(int(input())):
	n = int(input())
	rounds = 2 * n // 2
	print(rounds)
	c = 1
	d = 2
	for j in range(rounds):
		print(n)
		for i in range(1, n + 1):
			print(i, c, d)
		c = (c + 1) % n + 1
		d = (d + 1) % n + 1


for t in range(0, int(input())):
	n = int(input())
	print(n)
	for i in range(0, n):
		print(n)
		for j in range(0, n):
			xx = i + 1
			yy = i + 2
			if yy == n + 1:
				yy = 1
			print(j + 1, end=' ')
			print(xx, end=' ')
			print(yy)


t = int(input())
for _ in range(t):
	(n, x) = (int(input().strip()), 0)
	print(n)
	for i in range(n):
		print(n)
		for j in range(n):
			print(j + 1, (j + x) % n + 1, (j + x + 1) % n + 1, sep=' ', end='\n')
		x += 1


for _ in range(int(input())):
	n = int(input())
	if n % 2 == 0:
		print(n)
		for i in range(n // 2):
			for j in range(2):
				print(n)
				l = [(i, i + 1) for i in range(1, n, 2)]
				ln = len(l)
				c = i
				for k in range(1, n + 1, 2):
					print(k, l[c][0], l[c][1])
					print(k + 1, l[c][0], l[c][1])
					if c == ln - 1:
						c = 0
						for nt in range(k + 2, n + 1, 2):
							print(nt, l[c][0], l[c][1])
							print(nt + 1, l[c][0], l[c][1])
							c += 1
						break
					c += 1
	else:
		print(n)
		l = [(i, i + 1) for i in range(1, n)]
		l.append((n, 1))
		ln = len(l)
		for i in range(n):
			print(n)
			c = i
			for k in range(1, n + 1):
				print(k, l[c][0], l[c][1])
				if c == ln - 1:
					c = 0
					for nt in range(k + 1, n + 1):
						print(nt, l[c][0], l[c][1])
						c += 1
					break
				c += 1


for j in range(int(input())):
	n = int(input())
	l = []
	print(n)
	for i in range(1, n + 1):
		l.append((i, min(i, i % n + 1), max(i, i % n + 1)))
	for k in range(n):
		print(n)
		for j in l:
			print(j[0], end=' ')
			print(j[1] + k if j[1] + k <= n else (j[1] + k) % n, end=' ')
			print(j[2] + k if j[2] + k <= n else (j[2] + k) % n, end=' ')
			print()


for _ in range(int(input())):
	n = int(input())
	if n & 1:
		print(n - 3 + 3)
		for x in range(1, n - 3, 2):
			for t in range(2):
				print(n)
				for j in range(n):
					print(j + 1, x, x + 1)
		print(n)
		for j in range(n):
			print(j + 1, n - 2, n - 1)
		print(n)
		for j in range(n):
			print(j + 1, n - 2, n)
		print(n)
		for j in range(n):
			print(j + 1, n - 1, n)
	else:
		print(n)
		for x in range(1, n, 2):
			for t in range(2):
				print(n)
				for j in range(n):
					print(j + 1, x, x + 1)


for _ in range(int(input())):
	n = int(input())
	l = list(range(1, n + 1))
	print(n)
	for _ in range(n):
		print(n)
		l.append(l[0])
		l.pop(0)
		for i in range(1, n + 1):
			if i != n:
				print('%i %i %i' % (l[i - 1], i, i + 1))
			else:
				print('%i %i %i' % (l[i - 1], 1, n))


test = int(input())
for t in range(0, test):
	n = int(input())
	l = []
	for i in range(1, n):
		l.append((i, i + 1))
	l.append((n, 1))
	print(n)
	for i in range(0, n):
		print(n)
		for j in range(0, n):
			print(j + 1, end=' ')
			for x in l[j]:
				print(x, end=' ')
			print()
		l.append(l[0])
		l.remove(l[0])


T = int(input())
for t in range(T):
	temp = 0
	dishes = []
	n = int(input())
	for i in range(2):
		for x in range(n):
			dishes.append(x + 1)
	rounds = n
	print(rounds)
	for Round in range(1, n + 1):
		print(n)
		i = temp
		for judge in range(1, n + 1):
			if i >= len(dishes):
				i = 0
			print(judge, end='')
			print(' %d %d' % (dishes[i], dishes[i + 1]))
			i += 2
		temp += 2


T = int(input())
for test in range(T):
	numbers = []
	N = int(input())
	for i in range(N):
		numbers.append(i + 1)
	print(N)
	current = 0
	for i in range(N):
		print(N)
		for k in range(N):
			print(k + 1, numbers[current % N], numbers[(current + 1) % N])
			current += 1
		current += 1


t = int(input())
l1 = 1
l2 = 2
while t != 0:
	t = t - 1
	n = int(input())
	k = n
	d1 = 1
	d2 = 2
	if n == 1:
		print(1)
		print(n)
		print(1, 1, 1)
		continue
	print(k)
	for i in range(k):
		print(k)
		for j in range(k):
			print(j + 1, d1, d2)
		d1 = d1 + 1
		d2 = d2 + 1
		if d2 > k:
			d2 = l1


t = int(input())
for _ in range(t):
	judges = int(input())
	(start, end) = (1, 2)
	print(judges)
	for i in range(judges - 1):
		print(judges)
		for j in range(judges):
			print(j + 1, start, end)
		start += 1
		end += 1
	print(judges)
	start = 1
	end -= 1
	for i in range(judges):
		print(i + 1, start, end)


for _ in range(int(input())):
	n = int(input())
	print(n)
	for i in range(n):
		print(n)
		for j in range(0, n):
			print(j + 1, (i + j) % n + 1, (i + j + 1) % n + 1)


t = int(input())
for test in range(t):
	n = int(input())
	print(n)
	nums = list(range(1, n + 1))
	for i in range(n):
		print(n)
		tmp = i
		for j in range(1, n + 1):
			print(j, nums[tmp], nums[(tmp + 1) % n])
			tmp = (tmp + 1) % n


t = int(input())
for i in range(t):
	n = int(input())
	r = n
	print(r)
	l = list(range(1, r + 1))
	k = []
	for j in range(r):
		k.append([l[j], l[(j + 1) % r]])
	for j in range(r):
		print(r)
		for m in range(r):
			print(m + 1, k[(j + m) % r][0], k[(j + m) % r][1])


from itertools import repeat
for _ in repeat(None, int(input())):
	n = int(input())
	print(n)
	for i in range(n):
		print(n)
		for j in range(n):
			print(j + 1, end=' ')
			print(str(i % n + 1) + ' ' + str((i + 1) % n + 1))


t = int(input().strip())
for a0 in range(t):
	rounds = int(input().strip())
	print(rounds)
	judges = [None] * rounds
	arr = [j + 1 for j in range(rounds)] + [j + 1 for j in range(rounds)]
	for i in range(rounds):
		judges[i] = arr[2 * i:] + arr[:2 * i]
	for i in range(rounds):
		print(rounds)
		for j in range(rounds):
			print(j + 1, judges[j][2 * i], judges[j][2 * i + 1])


t = int(input())
while t > 0:
	n = int(input())
	print(n)
	j = 1
	l = 2
	for k in range(n):
		print(n)
		for i in range(1, n + 1):
			print(i, end=' ')
			print(j, end=' ')
			print(l, end=' ')
			print()
		j += 1
		l += 1
		if l > n:
			l = 1
	t -= 1


import io
import sys

def test_data():
	return io.StringIO('2\n2\n3')

def get_input(source):
	with source as lines:
		t = int(next(lines))
		for _ in range(t):
			n = int(next(lines))
			yield (n,)

def calc(n):
	rounds = []
	for i in range(n):
		rounds.append([])
		r = rounds[i]
		for j in range(n):
			r.append((j + 1, (j + i) % n + 1, (j + i + 1) % n + 1))
	return rounds
inp = test_data() if '-test' in sys.argv else sys.stdin
for args in get_input(inp):
	rounds = calc(*args)
	print(len(rounds))
	for r in rounds:
		print(len(r))
		for judge in r:
			print('{} {} {}'.format(*judge))


for t in range(int(input())):
	n = int(input())
	print(n)
	offset = 0
	for i in range(n):
		print(n)
		for j in range(n):
			x = offset + n
			y = x + 1
			print(j + 1, x % n + 1, y % n + 1)
			offset += 1
		offset += 1