Recall that a permutation of length $n$ is an array where each element from $1$ to $n$ occurs exactly once.

For a fixed positive integer $d$, let's define the cost of the permutation $p$ of length $n$ as the number of indices $i$ $(1 \le i < n)$ such that $p_i \cdot d = p_{i + 1}$.

For example, if $d = 3$ and $p = [5, 2, 6, 7, 1, 3, 4]$, then the cost of such a permutation is $2$, because $p_2 \cdot 3 = p_3$ and $p_5 \cdot 3 = p_6$.

Your task is the following one: for a given value $n$, find the permutation of length $n$ and the value $d$ with maximum possible cost (over all ways to choose the permutation and $d$). If there are multiple answers, then print any of them.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 500$) — the number of test cases.

The single line of each test case contains a single integer $n$ ($2 \le n \le 2 \cdot 10^5$).

The sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.


-----Output-----

For each test case, print the value $d$ in the first line, and $n$ integers in the second line — the permutation itself. If there are multiple answers, then print any of them.


-----Examples-----

Input
2
2
3
Output
2
1 2
3
2 1 3


-----Note-----

None

Source: codeforces | Difficulty: EASY
Tags: Greedy algorithms


Solutions:
for _ in range(int(input())):
	n = int(input())
	list1 = []
	for num in range(1, n + 1, 2):
		while num <= n:
			list1.append(num)
			num *= 2
	print(2)
	print(' '.join(map(str, list1)))


def find(n):
	if n == 2:
		return [1, 2]
	out = []
	current = 1
	while current <= n:
		out.append(current)
		next = current * 2
		while next <= n:
			out.append(next)
			next *= 2
		current += 2
	return out
t = int(input())
for _ in range(t):
	n = int(input())
	ans = [str(elem) for elem in find(n)]
	print(2)
	print(' '.join(ans))


from re import I

def solve(n):
	d = 2
	print(d)
	out = []
	i = 1
	while i <= n:
		temp = i
		while temp <= n:
			out.append(temp)
			temp *= 2
		i += 2
	print(' '.join(map(str, out)))
	pass

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		solve(n)
	return
main()


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	print(2)
	ans = []
	for i in range(1, n + 1, 2):
		while i <= n:
			ans.append(i)
			i *= 2
	print(' '.join(map(str, ans)))


tc = int(input())
while tc > 0:
	n = int(input())
	A = []
	i = 1
	while i <= n:
		j = i
		while j <= n:
			A.append(str(j))
			j = j * 2
		i += 2
	print(2)
	print(' '.join(A))
	tc = tc - 1


for i in range(int(input())):
	n = int(input())
	a = []
	for j in range(1, n + 1, 2):
		k = j
		while k <= n:
			a.append(k)
			k *= 2
	print(2)
	print(' '.join(map(str, a)))


for i in range(int(input())):
	n = int(input())
	pLst = []
	for j in range(1, n + 1, 2):
		while j <= n:
			pLst.append(j)
			j = j * 2
	print(2)
	print(' '.join(list(map(str, pLst))))


def solve(n):
	arr = []
	for i in range(1, n + 1):
		if i % 2 == 0:
			continue
		j = i
		while j <= n:
			arr.append(j)
			j *= 2
	return arr
T = int(input())
for _ in range(T):
	n = int(input())
	print(2)
	arr = solve(n)
	print(' '.join(map(str, arr)))


t = int(input())
for _ in range(t):
	n = int(input())
	was = [False] * (n + 1)
	res = []
	for i in range(1, n + 1):
		if was[i]:
			continue
		x = i
		while x <= n:
			res.append(x)
			was[x] = True
			x *= 2
	print(2)
	print(' '.join(map(str, res)))


t = int(input())
for case in range(t):
	n = int(input())
	a = []
	for i in range(n // 2):
		i = 2 * i + 1
		a.append(i)
		while 2 * i <= n:
			i *= 2
			a.append(i)
	if n % 2 == 1:
		a.append(n)
	astr = ' '.join([str(i) for i in a])
	print(2)
	print(astr)


import math
t = int(input())
for test in range(t):
	n = int(input())
	print(2)
	ansLis = []
	usedNumI = [0 for i in range(n + 2)]
	usedNumI[0] = 1
	for i in range(n + 1):
		if not usedNumI[i]:
			while i <= n:
				usedNumI[i] = 1
				ansLis.append(i)
				i *= 2
	print(' '.join(list(map(str, ansLis))))


import sys
import math
from collections import defaultdict, Counter, deque
input = sys.stdin.readline

def I():
	return input()

def II():
	return int(input())

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

def LI():
	return list(input().split())

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

def GMI():
	return map(lambda x: int(x) - 1, input().split())

def LGMI():
	return list(map(lambda x: int(x) - 1, input().split()))

def WRITE(out):
	return print('\n'.join(map(str, out)))

def WS(out):
	return print(' '.join(map(str, out)))

def WNS(out):
	return print(''.join(map(str, out)))
t = int(input())
for _ in range(t):
	n = int(input())
	print(2)
	ans = []
	for i in range(1, n + 1, 2):
		j = i
		group = []
		while j <= n:
			group.append(j)
			j *= 2
		ans += group
	WS(ans)


for _ in range(int(input())):
	n = int(input())
	d = 2
	a = [0] * n
	start = 1
	current = start
	for i in range(n):
		a[i] = current
		current *= d
		if current > n:
			start += 2
			current = start
	print(d)
	print(' '.join((str(i) for i in a)))


for t in range(int(input())):
	n = int(input())
	i = 1
	a = []
	while i <= n:
		a.append(i)
		i *= 2
	for i in range(3, n + 1):
		if i & i - 1 != 0 and i % 2 != 0:
			c = i
			while c <= n:
				a.append(c)
				c *= 2
	print(2)
	print(' '.join((str(e) for e in a)))


t = int(input())
for ncase in range(1, t + 1):
	n = int(input())
	d = 2
	print(f'{d}')
	ans = ''
	s = [i for i in range(1, n + 1)]
	s1 = []
	for i in range(1, n + 1, 2):
		s0 = i
		if s[0] > n / 2 + 2:
			s1 += [str(i) for i in range(i, n + 1, 2)]
			break
		t = [s0]
		while s0 * 2 <= n:
			s0 *= 2
			t.append(s0)
		s1 += [str(i) for i in t]
	print(' '.join(s1))


t = int(input())
for _ in range(t):
	n = int(input())
	d = 2
	p = []
	used = {}
	for i in range(1, n + 1):
		if i not in used:
			p.append(i)
			q = i
			used[i] = 1
			while q < n:
				q *= d
				if q <= n and q not in used:
					used[q] = 1
					p.append(q)
	print(d)
	print(' '.join(map(str, p)))


numTestCases = int(input())
for case in range(numTestCases):
	n = int(input())
	d = 2
	arr = [1]
	number = 3
	while len(arr) < n:
		for j in range(0, n - 1):
			if arr[j] * 2 <= n:
				arr.append(arr[j] * 2)
			else:
				arr.append(number)
				number += 2
	print(d)
	for t in range(len(arr)):
		arr[t] = str(arr[t])
	print(' '.join(arr))


t = int(input())
while t:
	n = int(input())
	sol = []
	seen = set()
	for i in range(1, n + 1):
		if i in seen:
			continue
		cur = i
		while cur <= n:
			seen.add(cur)
			sol.append(str(cur))
			cur *= 2
	for i in range(1, n + 1):
		if not i in seen:
			sol.append(str(i))
	print(2)
	print(' '.join(sol))
	t -= 1


for i in range(int(input())):
	n = int(input())
	print(2)
	s = ''
	for i in range(0, n + 1, 2):
		j = i + 1
		while j <= n:
			s += str(j) + ' '
			j = j * 2
	print(s)


def answer(n: int):
	d = 2
	array = [False] * n
	ans = ''
	for (num, b) in enumerate(array, 1):
		if b:
			continue
		while num <= n:
			array[num - 1] = True
			ans += str(num) + ' '
			num *= d
	return ans.strip()

def main():
	for _ in range(int(input())):
		n = int(input())
		print(2)
		print(answer(n))
main()


x = int(input())
for jj in range(x):
	n = int(input())
	ans = [0] * n
	t = set(range(1, n + 1))
	k = 0
	for j in range(1, n + 1):
		i = j
		while i in t:
			t.remove(i)
			ans[k] = i
			k += 1
			i *= 2
	print(2)
	print(' '.join([str(p) for p in ans]))


t = int(input())
for _ in range(t):
	n = int(input())
	permutation = ''
	for i in range(1, n + 1, 2):
		while i <= n:
			permutation += f'{i} '
			i <<= 1
	print(2)
	print(permutation)


t = int(input())
for i in range(t):
	n = int(input())
	print(2)
	k = 1
	ans = ''
	while k <= n // 2:
		q = k
		while q <= n:
			ans += str(q) + ' '
			q *= 2
		k += 2
	for j in range(n // 2 + 1 + n // 2 % 2, n + 1, 2):
		ans += str(j) + ' '
	print(ans)


iter = int(input())
for i in range(iter):
	n = int(input())
	s = ''
	for i in range(1, n + 1, 2):
		ind = i
		while ind <= n:
			s += str(ind) + ' '
			ind *= 2
	print(2)
	print(s)


for i in range(int(input())):
	n = int(input())
	print('2')
	p = 1
	s = ''
	while p <= n:
		x = p
		while x <= n:
			s += str(x) + ' '
			x *= 2
		p += 2
	print(s)


def op(s, p):
	A = ''
	for se in s:
		A += str(se) + p
	return A

def kil_(n):
	k = []
	j = 1
	while len(k) < n:
		k.append(j)
		i = j
		while i * 2 <= n:
			i *= 2
			k.append(i)
		j = j + 2
	return '2' + '\n' + op(k, ' ')[:-1]

def kil(a):
	t = int(input())
	A = ''
	for i in range(t):
		A += kil_(a()) + '\n'
	print(A[:-1])

def h():
	return int(input())
kil(h)


import math

def main():
	n = int(input())
	lst = []
	needed = [True] * (n + 1)
	base = 0
	lim = math.ceil(n * 0.5)
	while base <= lim:
		base += 1
		if not needed[base]:
			continue
		i = base
		while i <= n:
			if not needed[i]:
				continue
			lst.append(i)
			needed[i] = False
			i *= 2
	for (i, isNeeded) in enumerate(needed):
		if i == 0:
			continue
		if isNeeded:
			lst.append(i)
	string = ''
	for num in lst:
		string += str(num) + ' '
	print('2')
	print(string)
t = int(input())
for i in range(t):
	main()


for _ in range(int(input())):
	n = int(input())
	print(2)
	vis = [False for i in range(n + 10)]
	pri = ''
	for i in range(1, n + 1):
		if not vis[i]:
			ind = i
			while ind <= n:
				pri += str(ind) + ' '
				vis[ind] = True
				ind *= 2
	print(pri)


T = int(input())
for t in range(T):
	n = int(input())
	marker = [False] * (n + 1)
	result = []
	for i in range(n, 0, -1):
		if not marker[i]:
			marker[i] = True
			result.append(i)
		while i / 2 == i // 2 and (not marker[i // 2]):
			result.append(i // 2)
			marker[i // 2] = True
			i = i // 2
	print(2)
	result.reverse()
	for i in range(len(result)):
		result[i] = str(result[i])
	print(' '.join(result))


import math
for _ in range(int(input())):
	n = int(input())
	l = [1]
	j = 2
	checks = list(range(2, n + 1))
	while j <= n:
		if checks[j - 2] == None:
			j += 1
			continue
		counter = j
		while counter <= n:
			l.append(counter)
			checks[counter - 2] = None
			counter *= 2
		j += 1
	print(2)
	result = []
	for i in l:
		result.append(str(i))
	print(' '.join(result))


def solve(n):
	for i in range(1, n + 1, 2):
		while i <= n:
			print(i, end=' ')
			i *= 2
for _ in range(int(input())):
	n = int(input())
	print(2)
	solve(n)
	print()


for _ in range(int(input())):
	n = int(input())
	print(2)
	z = [False for i in range(1, n + 10)]
	l = ''
	for i in range(1, n + 1):
		if not z[i]:
			j = i
			while j < n + 1:
				l += str(j) + ' '
				z[j] = True
				j *= 2
	print(l)


for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(1, n + 1, 2):
		while i <= n:
			a.append(i)
			i *= 2
	print(2)
	print(*a)


for _ in range(int(input())):
	n = int(input())
	res = ''
	gone = [0 for _ in range(n)]
	for i in range(n):
		if gone[i] == 0:
			res += str(i + 1) + ' '
			gone[i] = 1
			now = 2 * (i + 1)
			while now <= n:
				res += str(now) + ' '
				gone[now - 1] = 1
				now *= 2
	print('2')
	print(res[:len(res) - 1])


for _ in range(int(input())):
	n = int(input())
	print(2)
	l = []
	for i in range(1, n + 1, 2):
		j = i
		l.append(i)
		while True:
			j *= 2
			if j <= n:
				l.append(j)
			else:
				break
	print(*l)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		print(2)
		print(1, end=' ')
		array = [True] * (n + 1)
		for i in range(2, n + 1):
			if array[i]:
				tmp = i
				while tmp <= n:
					print(tmp, end=' ')
					array[tmp] = False
					tmp *= 2
		print()
main()


t = int(input())
for _ in range(t):
	n = int(input())
	print(2)
	l = []
	for i in range(1, n + 1, 2):
		v = i
		l.append(i)
		while 2 * v <= n:
			v = 2 * v
			l.append(v)
	print(*l)


class Permutation:

	def findCost(self, n):
		d = 2
		arr = []
		for i in range(1, n // 2 + 1, 2):
			j = i
			while j <= n:
				arr.append(j)
				j *= d
		for i in range(1, n + 1, 2):
			if i > n // 2:
				arr.append(i)
		print(d)
		for i in arr:
			print(i, end=' ')
		print()
		return
T = int(input())
while T:
	T -= 1
	n = int(input())
	Permutation().findCost(n)


def permutation():
	for _ in range(int(input())):
		a = int(input())
		odd = [2]
		c = [1]
		for i in range(2, a + 1):
			if i % 2 == 1:
				odd.append(i)
		for i in range(len(odd)):
			c.append(odd[i])
			while True:
				if c[-1] * 2 <= a:
					c.append(c[-1] * 2)
				else:
					break
		print(2)
		print(*c)
permutation()


T = int(input())
q = []
for i in range(T):
	n = int(input())
	q.append(n)

def solve(n):
	print(2)
	written = [False for _ in range(n + 1)]
	for i in range(1, n + 1):
		if written[i]:
			continue
		print(i, end=' ')
		target = i * 2
		while target <= n:
			print(target, end=' ')
			written[target] = True
			target *= 2
	print()
for n in q:
	solve(n)


t = int(input())
for i in range(t):
	n = int(input())
	print(2)
	a = []
	for x in range(1, 2 * (n // 2) + n % 2 + 2, 2):
		s = x
		while s <= n:
			a.append(s)
			s *= 2
	print(*a)


def ss(n):
	a = []
	d = [False] * (n + 1)
	for i in range(1, n + 1):
		if d[i] == False:
			j = i
			while j <= n:
				if d[j] == False:
					a.append(j)
					d[j] = True
				j = j * 2
	return a
for _ in range(int(input())):
	n = int(input())
	a = ss(n)
	print(2)
	print(*a)


for _ in range(int(input())):
	n = int(input())
	ans = []
	i = 1
	while i <= n:
		j = i
		while j <= n:
			ans.append(j)
			j *= 2
		i += 2
	print(2)
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	print(2)
	for i in range(1, n + 1, 2):
		t = i
		while t <= n:
			print(t, end=' ')
			t *= 2
	print()


t = int(input())
for i in range(t):
	num = int(input())
	print(2)
	for i in range(1, num + 1, 2):
		ans = i
		while ans <= num:
			print(ans, end=' ')
			ans *= 2
	print()


t = int(input())
D = []
L = []
for i in range(t):
	n = int(input())
	l = []
	for j in range(1, n + 1, 2):
		pro = j
		while pro < n + 1:
			l.append(pro)
			pro *= 2
	L.append(l)
for k in range(t):
	print(2)
	print(*L[k])


ans = []
for i in range(int(input())):
	n = int(input())
	d = 2
	l = []
	for i in range(1, (n + 1) // 2 + 1):
		j = 2 * i - 1
		l.append(j)
		while d * j <= n:
			l.append(d * j)
			j = d * j
	ans.append(l)
for i in ans:
	print('2')
	print(*i)


import heapq
import math
import string
from collections import deque, Counter, defaultdict

def solve():
	N = int(input())
	if N == 2:
		print(2)
		print(1, 2)
	else:
		d = 2
		res = []
		for i in range(1, N + 1):
			if i % 2 == 0:
				continue
			j = i
			while j <= N:
				res.append(j)
				j *= 2
		print(d)
		print(*res)
T = int(input())
for test_case in range(T):
	solve()


for _ in range(int(input())):
	n = int(input())
	print(2)
	for v in range(1, n + 1, 2):
		k = v
		while k <= n:
			print(k, end=' ')
			k *= 2
	print()


for t in range(int(input())):
	n = int(input())
	l = []
	for z in range(1, n + 1):
		if z % 2 == 1:
			l.append(z)
			while 2 * z <= n:
				l.append(2 * z)
				z *= 2
	print(2)
	print(*l)


t = int(input())
for x in range(t):
	n = int(input())
	d = 2
	print(str(d))
	res = []
	for i in range(1, n + 1):
		if i % 2 != 0:
			j = i
			while j <= n:
				res.append(j)
				j = j * 2
	print(*res)


for _ in range(int(input())):
	n = int(input())
	mass = []
	print(2)
	for i in range(1, n + 1, 2):
		x = i
		while x <= n:
			print(x, end=' ')
			x *= 2
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	mas = []
	for i in range(1, n + 1, 2):
		j = i
		while j <= n:
			mas.append(j)
			j *= 2
	print(2)
	print(*mas)


t = int(input())
for _ in range(0, t):
	n = int(input())
	print(2)
	list1 = [1]
	k = 1
	while k * 2 <= n:
		k = k * 2
		list1.append(k)
	for i in range(3, n + 1, 2):
		k = i
		while k <= n:
			list1.append(k)
			k = k * 2
	print(*list1)


y = int(input())
for i in range(y):
	n = int(input())
	d = 2
	print(d)
	for i in range(1, n + 1, d):
		j = i
		while j <= n:
			print(j, end=' ')
			j *= d
	print('')


for _ in range(int(input())):
	n = int(input())
	print(2)
	arr = []
	arr1 = [x for x in range(2, n + 1)]
	for i in range(1, n + 1, 2):
		j = i
		while j <= n:
			arr.append(j)
			j = 2 * j
	print(*arr)


for _ in range(int(input())):
	n = int(input())
	print(2)
	s = '1'
	seen = set()
	for i in range(2, n + 1):
		if i not in seen:
			s += ' ' + str(i)
			seen.add(i)
			j = i
			while j * 2 <= n and j * 2 not in seen:
				j *= 2
				s += ' ' + str(j)
				seen.add(j)
	print(s)


import sys

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

def si():
	return input()

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

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

def li():
	return list(mi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stout = open('output.txt', 'w')

def main():
	for i in range(ii()):
		n = ii()
		a = [0] * (n + 1)
		print(2)
		for i in range(1, n + 1, 2):
			if a[i] != 1:
				print(i, end=' ')
				k = i * 2
				a[i] = 1
				while k <= n:
					print(k, end=' ')
					a[k] = 1
					k *= 2
			else:
				continue
		print('')
main()


t = int(input())
for i in range(t):
	n = int(input())
	res = [1]
	checkPrime = [True] * (n + 1)
	checkPrime[0] = False
	checkPrime[1] = False
	for i in range(n + 1):
		if checkPrime[i] == True:
			j = i
			while j <= n:
				res.append(j)
				checkPrime[j] = False
				j *= 2
	print(2)
	print(*res)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	ans = []
	count = 0
	j = 1
	k = 1
	while count < n:
		k = j
		while k <= n:
			ans.append(k)
			k *= 2
			count += 1
		j += 2
	print('2')
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	arr = [True for _ in range(n + 1)]
	arr[1] = True
	ans = [1]
	for i in range(2, n + 1):
		t = i
		if arr[t]:
			while t <= n:
				ans.append(t)
				arr[t] = False
				t *= 2
	print(2)
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	print(2)
	ans = []
	p = 1
	while p <= n:
		q = p
		while q <= n:
			ans.append(q)
			q *= 2
		p += 2
	print(*ans)


for i in range(int(input())):
	a = int(input())
	print(2)
	b = [0] * (a + 1)
	for j in range(1, a + 1):
		if b[j] == 0:
			d = j
			while d <= a:
				print(d, end=' ')
				b[d] = 1
				d *= 2
	print()


t = int(input())

def solve(n):
	arr = []
	for i in range(1, n + 1, 2):
		temp = []
		x = i
		while x <= n:
			temp.append(x)
			x = x * 2
		for j in temp:
			arr.append(j)
	return arr
while t > 0:
	n = int(input())
	print(2)
	x = solve(n)
	for i in x:
		print(i, end=' ')
	print()
	t = t - 1


for t in range(int(input())):
	n = int(input())
	a = [1] * (n + 1)
	l = []
	for i in range(1, n + 1):
		if a[i]:
			r = i
			while r <= n:
				l.append(r)
				a[r] = 0
				r = r << 1
	print(2)
	print(*l)


t = int(input())
for _ in range(t):
	n = int(input())
	z = [0] * (n + 1)
	r = []
	for i in range(1, n + 1):
		if z[i] == 0:
			j = i
			while j <= n:
				r.append(j)
				z[j] = 1
				j *= 2
	print(2)
	print(*r)


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	ans = []
	S = set()
	for i in range(1, n + 1):
		if i in S:
			continue
		num = i
		while num <= n:
			ans.append(num)
			S.add(num)
			num *= 2
	print(2)
	print(*ans)
for _ in range(int(input())):
	solve()


import random
O = random.randint(1, 10 ** 5)

def main():
	N = int(input())
	for _ in range(N):
		n = int(input())
		arr = []
		used = set()
		for i in range(1, n + 1):
			while i <= n:
				if i + O in used:
					break
				arr.append(i)
				used.add(i + O)
				i *= 2
		print(2)
		print(*arr)

def init():
	import os
	import sys
	sys.setrecursionlimit(2 * 10 ** 6)
	if 'CP_LOCAL_ENV' in os.environ:
		sys.stdin = open('cf_test_b.txt')
init()
main()


for _ in range(int(input())):
	n = int(input())
	d = 2
	lis = []
	for i in range(1, n + 1, 2):
		odd = i
		while odd < n + 1:
			lis.append(odd)
			odd *= d
	print(d)
	print(*lis)


for i in range(int(input())):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
	elif n == 3:
		print(1, 2, 3)
	else:
		x = 1
		while True:
			if x > n:
				break
			print(int(x), end=' ')
			x *= 2
		for i in range(3, n // 2 + 1, 2):
			x = i
			while x <= n:
				print(int(x), end=' ')
				x *= 2
		for i in range(n // 2 + 1, n + 1):
			if i % 2 == 1:
				print(i, end=' ')
		print()


from collections import deque

def solve():
	n = int(input())
	isSet = [False] * (n + 1)
	isSet[0] = True
	queue = deque([])
	for i in range(n, 0, -1):
		if isSet[i] == False:
			if i % 2 == 0:
				x = i
				while x:
					if isSet[x]:
						break
					isSet[x] = True
					queue.appendleft(x)
					if x % 2 == 0:
						x //= 2
					else:
						break
			else:
				isSet[i] = True
				queue.appendleft(i)
	print(2)
	print(*queue)
t = int(input())
for _ in range(t):
	solve()


import math
t = int(input())
for z in range(t):
	n = int(input())
	print(2)
	l = []
	k = int(math.log2(n))
	for i in range(k + 1):
		print(2 ** i, end=' ')
	for i in range(3, n + 1, 2):
		j = i
		while j <= n:
			print(j, end=' ')
			j = 2 * j
	print()


t = int(input())
while t > 0:
	print(2)
	print()
	a = 1
	n = int(input())
	for a in range(1, n + 1, 2):
		while a <= n:
			print(a, end=' ')
			a = a * 2
	t = t - 1
	print()