Numbers $1, 2, 3, \dots n$ (each integer from $1$ to $n$ once) are written on a board. In one operation you can erase any two numbers $a$ and $b$ from the board and write one integer $\frac{a + b}{2}$ rounded up instead.

You should perform the given operation $n - 1$ times and make the resulting number that will be left on the board as small as possible. 

For example, if $n = 4$, the following course of action is optimal:  choose $a = 4$ and $b = 2$, so the new number is $3$, and the whiteboard contains $[1, 3, 3]$;  choose $a = 3$ and $b = 3$, so the new number is $3$, and the whiteboard contains $[1, 3]$;  choose $a = 1$ and $b = 3$, so the new number is $2$, and the whiteboard contains $[2]$. 

It's easy to see that after $n - 1$ operations, there will be left only one number. Your goal is to minimize it.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases.

The only line of each test case contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the number of integers written on the board initially.

It's guaranteed that the total sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$.


-----Output-----

For each test case, in the first line, print the minimum possible number left on the board after $n - 1$ operations. Each of the next $n - 1$ lines should contain two integers — numbers $a$ and $b$ chosen and erased in each operation.


-----Example-----
Input
1
4

Output
2
2 4
3 3
3 1

Difficulty: EASY
Tags: Constructive algorithms

Implementation

Greedy algorithms

Mathematics

Data structures
Skill types: Data structures

Greedy algorithms

Starter code:

Solutions:
t = int(input())
while t:
	t -= 1
	n = int(input())
	print(2)
	if n > 2:
		print(n, n - 2)
		print(n - 1, n - 1)
		n -= 1
		while n > 2:
			print(n, n - 2)
			n -= 1
	else:
		print(1, 2)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(range(1, n + 1))
	ans = []
	for j in range(n - 1):
		a = l.pop()
		b = l.pop()
		l.append((a + b + 1) // 2)
		ans.append((a, b))
	print(l[0])
	for j in range(n - 1):
		print(ans[j][0], ans[j][1])


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


t = int(input())
for q in range(t):
	n = int(input())
	print(2)
	m = n
	i = 1
	while True:
		print(m, n - i)
		if (m + n - i) % 2 == 1:
			m = (m + n - i + 1) // 2
		else:
			m = (m + n - i) // 2
		if i >= n - 1:
			break
		i += 1


for i in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(2, 1)
	else:
		print(2)
		print(n - 2, n)
		print(n - 1, n - 1)
		for i in range(n - 3, 0, -1):
			print(i + 2, i)


import heapq
import collections
from math import log2
import itertools
from functools import lru_cache
from sys import setrecursionlimit as srl
srl(2 * 10 ** 6)
N = 200001

def solve(n):
	print(2)
	res = []
	if n == 2:
		res.append([1, 2])
	else:
		res.append([n, n - 2])
		res.append([n - 1, n - 1])
		i = n - 3
		while i >= 1:
			res.append([i, i + 2])
			i -= 1
	return res
t = int(input())
for tc in range(1, t + 1):
	n = int(input())
	d = solve(n)
	for x in d:
		print(*x)


for i in range(int(input())):
	n = int(input())
	x = n - 1
	z = []
	for i in range(n - 1):
		if i == 0:
			z.append(n)
			z.append(x)
			y = (x + n) % 2
			if y > 0:
				t = (x + n) // 2
				t += 1
				x -= 1
			else:
				t = (x + n) // 2
				x -= 1
		else:
			z.append(t)
			z.append(x)
			y = (x + t) % 2
			if y > 0:
				t = (x + t) // 2
				t += 1
				x -= 1
			else:
				t = (x + t) // 2
				x -= 1
	print(t)
	o = len(z)
	for i in range(0, o, 2):
		print(z[i], z[i + 1])


def solve(n):
	print(2)
	if n == 2:
		print(1, 2)
		return
	print(n - 2, n)
	print(n - 1, n - 1)
	for i in range(n - 3, 0, -1):
		print(i, i + 2)
for i in range(int(input())):
	n = int(input())
	solve(n)


for _ in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(n, n - 1)
		continue
	print(2)
	print(n, n - 2)
	print(n - 1, n - 1)
	n = n - 1
	while n > 2:
		print(n, n - 2)
		n -= 1


t = int(input())
for i in range(0, t):
	n = int(input())
	print(2)
	print(n, n - 1)
	if n > 2:
		i = n
		while i != 2:
			print(i, i - 2)
			i -= 1


for _ in range(int(input())):
	n = int(input())
	x = n
	ans = []
	for i in range(n - 1, 0, -1):
		ans.append([x, i])
		x = (x + i) // 2 if (x + i) % 2 == 0 else (x + i) // 2 + 1
	print(x)
	for pair in ans:
		print(' '.join(map(str, pair)))


for _ in range(int(input())):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
		continue
	t = True
	while n > 2:
		print(n - 2, n)
		if t:
			print(n - 1, n - 1)
			t = False
		n -= 1


for __ in range(int(input())):
	n = int(input())
	ar = [i for i in range(n, 0, -1)]
	ans = []
	num = ar[0]
	for i in range(1, n):
		ans.append([num, ar[i]])
		num = (num + ar[i] + 1) // 2
	print(num)
	for elem in ans:
		print(*elem)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	a.append([n, n - 1])
	ans = n
	curr = n - 2
	while curr > 0:
		a.append([curr, ans])
		ans = math.ceil((ans + curr) / 2)
		curr -= 1
	print(ans)
	for p in a:
		print(p[0], p[1])


tc = int(input())
for tcc in range(1, tc + 1):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	else:
		print(2)
		print(n, n - 2)
		print(n - 1, n - 1)
		for i in range(n - 1, 2, -1):
			print(i, i - 2)


for _ in range(int(input())):
	n = int(input())
	ans = []
	ans.append(n)
	ans.append(n - 1)
	print(2)
	print(*ans)
	while n >= 3:
		ans = [n, n - 2]
		print(*ans)
		n -= 1


def merge(a, b):
	if a > b:
		(a, b) = (b, a)
	print(a, b)
	return (a + b - 1) // 2 + 1

def solve(n):
	(odd, even) = (None, None)
	i = None
	while True:
		if not i:
			if n == 0:
				break
			i = n
			n -= 1
		if i % 2:
			if not odd:
				odd = i
				i = None
			else:
				odd_ = odd
				odd = None
				i = merge(odd_, i)
				continue
		elif not even:
			even = i
			i = None
		else:
			even_ = even
			even = None
			i = merge(even_, i)
			continue
	if even and odd:
		return merge(even, odd)
	elif even:
		return even
	elif odd:
		return odd
n_in = int(input())
for _ in range(n_in):
	print(2)
	solve(int(input()))


import os, sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		if n == 2:
			print(2)
			print(1, 2)
			continue
		print(2)
		print(n, n - 2)
		print(n - 1, n - 1)
		x = n - 1
		y = n - 3
		while y:
			print(x, y)
			x = (x + y) // 2
			y -= 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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def ceil(a, b):
	return (a + b - 1) // b
for _ in range(int(input())):
	n = int(input())
	print(2)
	orign = n
	count = 1
	print(n, n - 1)
	cur = ceil(n + n - 1, 2)
	n -= 1
	while count != orign - 1:
		cur = ceil(cur + n, 2)
		n -= 1
		print(cur, n)
		count += 1


t = int(input())
for i in range(t):
	n = int(input())
	a = []
	for j in range(1, n + 1):
		a.append(j)
	print(2)
	print(a.pop(n - 1), end=' ')
	print(a.pop(n - 3))
	a.append(n - 1)
	for k in range(n - 2):
		x1 = a.pop()
		x2 = a.pop()
		print(x1, end=' ')
		print(x2)
		a.append(int(x1 + x2) // 2)


t = int(input())
for _ in range(t):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
		continue
	arr = list(range(1, n + 1))
	moves = []
	while len(arr) > 1:
		if (arr[-1] + arr[-2]) % 2 == 0:
			moves.append([arr[-1], arr[-2]])
			nextVal = (arr[-1] + arr[-2]) // 2
			arr.pop()
			arr.pop()
			arr.append(nextVal)
		else:
			moves.extend([[arr[-1], arr[-3]], [arr[-2], arr[-2]]])
			nextVal = arr[-2]
			arr.pop()
			arr.pop()
			arr.pop()
			arr.append(nextVal)
	print(arr[0])
	for (a, b) in moves:
		print(a, b)


for _ in range(int(input())):
	n = int(input())
	b = n
	res = []
	for a in range(n - 1, 0, -1):
		res.append([a, b])
		b = (a + b + 1) // 2
	print(b)
	for p in res:
		print(*p)


import io
import os
import math
from collections import Counter, defaultdict, deque

def f(m):
	if m == 2:
		return [2, '1 2']
	length = m
	n = [i + 1 for i in range(m)]
	ans = []
	first = True
	while length > 1:
		if first:
			first = False
			ans.append('{} {}'.format(n[-1], n[-3]))
			n[-1] = math.ceil((n[-1] + n[-3]) // 2)
			del n[-3]
		else:
			ans.append('{} {}'.format(n[-1], n[-2]))
			n[-2] = math.ceil((n[-1] + n[-2]) // 2)
			del n[-1]
		length -= 1
	ans.insert(0, n[0])
	return ans
t = int(input())
result = []
for i in range(t):
	n = int(input())
	result.append(f(n))
for i in range(t):
	print(result[i][0])
	for step in range(1, len(result[i])):
		print(result[i][step])


import math
t = int(input())
for _ in range(t):
	n = int(input())
	lis = []
	prev = int(math.ceil((n + (n - 1)) / 2))
	lis.append((n - 1, n))
	for i in range(n - 2, 0, -1):
		lis.append((i, prev))
		prev = int(math.ceil((prev + i) / 2))
	print(prev)
	for i in lis:
		print(i[0], i[1])


for _ in range(int(input())):
	n = int(input())
	hold = n
	res = []
	for i in range(n - 1, 0, -1):
		res.append((hold, i))
		hold = (hold + i + 1) // 2
	print(hold)
	for i in res:
		print(*i)


def ans(n):
	print(2)
	print(str(n - 1) + ' ' + str(n))
	for i in range(n - 2):
		x = n - i
		print(str(x - 2) + ' ' + str(x))
	return
m = int(input())
for j in range(m):
	n = int(input())
	ans(n)


from sys import stdin, stdout

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		for i in range(int(R())):
			n = int(R())
			ans.append('2')
			prev = n
			for j in range(n - 1, 0, -1):
				ans.append(str(prev) + ' ' + str(j))
				prev = (prev + j) // 2 + (prev + j) % 2
		W('\n'.join(ans))
		return 0

def main():
	s = SOLVE()
	s.solve()
main()


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
		continue
	print(n - 2, n)
	print(n - 1, n - 1)
	for i in range(n - 3, 0, -1):
		print(i, i + 2)


test_case = int(input())
while test_case != 0:
	n = int(input())
	print(2)
	second = n
	first = n - 1
	for i in range(n, 1, -1):
		print(first, second)
		second = (second + first + 1) // 2
		first -= 1
	test_case -= 1


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


def ans(n):
	if n == 2:
		print('2')
		print('2 1')
	else:
		print('2')
		print(f'{n} {n - 2}')
		print(f'{n - 1} {n - 1}')
		for i in range(3, n):
			print(f'{n - i + 2} {n - i}')
CASES = int(input())
for i in range(CASES):
	n = int(input())
	ans(n)


import sys
from sys import stdin, stdout
import math
import random
import heapq
from collections import Counter
from functools import lru_cache
try:
	for _ in range(int(input())):
		n = int(input())
		if n == 2:
			print(2)
			print(1, 2)
		else:
			print(2)
			print(n, n - 2)
			print(n - 1, n - 1)
			for i in range(1, n - 2):
				print(n - i, n - i - 2)
except EOFError as e:
	print(e)


from sys import *
from math import *
from bisect import *
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = []
	m = []
	for i in range(1, n + 1):
		a.append(i)
	for i in range(n - 1):
		if i == 0:
			x = a[-1] + a[-2] + 1
		else:
			x = a[-1] + a[-2]
		y = x // 2
		m.append([a[-1], a[-2]])
		a.pop(-1)
		a.pop(-1)
		a.append(y)
	print(*a)
	for i in range(n - 1):
		print(*m[i])


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l = list(range(1, n + 1))
	res = []
	while len(l) > 1:
		b = l.pop()
		odd = b & 1
		j = None
		for i in range(len(l) - 1, -1, -1):
			if l[i] & 1 == odd:
				j = i
				break
		if j == None:
			a = l.pop()
		else:
			a = l.pop(i)
		l.append((a + b + 1) // 2)
		res.append((a, b))
		i = len(l) - 1
		while i > 0 and l[i] < l[i - 1]:
			(l[i], l[i - 1]) = (l[i - 1], l[i])
	print(l[0])
	for (x, y) in res:
		print(x, y)


for j in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	else:
		print(2)
		avg = (n + n - 2) // 2
		print(n, n - 2)
		print(avg, avg)
		for i in range(1, n - 2):
			if i >= 0:
				print(avg - 2, avg)
				avg = avg - 1
				continue
			break


import sys
input = sys.stdin.readline
print = sys.stdout.write
for _ in range(int(input())):
	n = int(input())
	s = [*range(1, n + 1)]
	ans = []
	while len(s) > 1:
		if len(s) == 2:
			(a, b) = s
			s = [(a + b + 1) // 2]
			ans.append((a, b))
			break
		if (s[-1] + s[-2]) % 2 == 0:
			(b, a) = (s.pop(), s.pop())
			ans.append((a, b))
			s.append((a + b) // 2)
		elif (s[-3] + s[-1]) % 2 == 0:
			(b, a) = (s.pop(), s.pop(-2))
			ans.append((a, b))
			s.append((a + b) // 2)
	print(str(s[0]) + '\n')
	for i in ans:
		print(str(i[0]) + ' ' + str(i[1]) + '\n')


from collections import deque

def next_num(a, b):
	return (a + b) // 2 + int((a + b) % 2 != 0)
for _ in range(int(input())):
	n = int(input())
	st = n - 1
	res = n
	print(2)
	for i in range(n - 1):
		print(st, res)
		res = next_num(st, res)
		st -= 1


import sys
input = lambda : sys.stdin.readline().rstrip()
from heapq import heappush, heappop
p_vals = []

def answer():
	n = int(input())
	p_vals = []
	ps = range(1, n + 1)
	for p in ps:
		heappush(p_vals, -p)
	out_txts = []
	for i in range(n - 1):
		val1 = -heappop(p_vals)
		val2 = -heappop(p_vals)
		out_txt = '%d %d' % (val2, val1)
		tmp = val1 + val2
		if tmp % 2 == 1:
			tmp = (tmp + 1) // 2
		else:
			tmp = tmp // 2
		heappush(p_vals, -tmp)
		out_txts.append(out_txt)
	out = -heappop(p_vals)
	print(out)
	for out_txt in out_txts:
		print(out_txt)
nn = int(input())
for i in range(nn):
	answer()


rw = int(input())
for wewq in range(rw):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	elif n == 3:
		print(2)
		print(1, 3)
		print(2, 2)
	else:
		print(2)
		print(n, n - 2)
		print(n - 1, n - 1)
		for i in range(n - 1, 2, -1):
			print(i, i - 2)


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(range(1, N + 1))
	print(2)
	while len(A) > 1:
		a = A.pop()
		b = A.pop()
		c = (a + b + 1) // 2
		print(a, b)
		A.append(c)


import sys
import math as mt
import bisect
input = sys.stdin.readline
t = int(input())
import collections
import heapq
p = 10 ** 9 + 7

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def solve():
	if n == 2:
		print(2)
		print(1, 2)
	else:
		ch = 0
		(a, b) = (n, n - 2)
		print(2)
		for i in range(n - 1):
			print(a, b)
			ch += 1
			if ch == 1:
				b = (a + b) // 2
				a = b
			else:
				a = (a + b) // 2
				b = a - 2
for _ in range(t):
	n = int(input())
	solve()


t = int(input())
q = []
for i in range(t):
	n = int(input())
	if n > 2:
		m = [[2], [n - 2, n], [n - 1, n - 1]]
	else:
		m = [[2], [n - 1, n]]
	n = n - 1
	while n >= 3:
		m.append([n - 2, n])
		n -= 1
	q.append(m)
for i in q:
	for j in i:
		for k in j:
			print(k, end=' ')
		print()


for _ in range(int(input())):
	n = int(input())
	print(2)
	print(n, n - 1)
	t = n
	for i in range(n - 2):
		print(t, t - 2)
		t -= 1


for _ in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(2, 1)
		continue
	print(2)
	print(n, n - 2)
	print(n - 1, n - 1)
	x = n - 1
	for i in range(n - 3):
		print(x, x - 2)
		x -= 1


import sys
c = sys.stdin.readline()
for i in range(0, int(c)):
	v = int(sys.stdin.readline())
	vals = []
	for j in range(0, v):
		vals.append(v - j)
	if v >= 3:
		sys.stdout.write('2' + '\n')
		sys.stdout.write(str(v) + ' ' + str(v - 2) + '\n')
		sys.stdout.write(str(v - 1) + ' ' + str(v - 1) + '\n')
		for j in range(3, v):
			sys.stdout.write(str(v + 2 - j) + ' ' + str(v - j) + '\n')
	elif v == 2:
		sys.stdout.write('2\n2 1\n')
	elif v == 1:
		sys.stdout.write('1\n')


for z in range(int(input())):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
	else:
		print(n, n - 2)
		print(n - 1, n - 1)
		for i in range(n - 1, 2, -1):
			print(i, i - 2)


for _ in range(int(input())):
	n = int(input())
	arr = []
	res = n
	for i in range(n - 1, 0, -1):
		arr.append((i, res))
		res = (i + res + 1) // 2
	print(res)
	for t in arr:
		print(*t)


t = int(input())
for k in range(t):
	n = int(input())
	print(2)
	print(n - 1, n)
	for i in range(n - 2):
		print(n - 2 - i, n - i)


t = int(input())
while t:
	print(2)
	t += -1
	n = int(input())
	if n == 2:
		print('2 1')
	elif n == 3:
		print('3 2\n3 1')
	else:
		print(n, n - 1)
		print(n, n - 2)
		for i in range(n - 1, 2, -1):
			print(i, i - 2)


from math import *
t = int(input())
while t:
	t = t - 1
	n = int(input())
	s = n
	print(2)
	for i in range(n - 1, 0, -1):
		print(s, i)
		s = ceil((s + i) / 2)


from collections import deque
mod = 10 ** 9 + 7
INF = float('inf')

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

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

def I():
	return int(input())
t = I()
for _ in range(t):
	n = I()
	A = list(range(1, n + 1))
	print(2)
	while len(A) > 1:
		a = A.pop()
		b = A.pop()
		c = (a + b + 1) // 2
		print(a, b)
		A.append(c)


def start(n):
	a = list(range(1, n + 1))
	s = []
	while len(a) > 1:
		(x, y) = (a[-1], a[-2])
		a[-2] = (x + y + 1) // 2
		a.pop()
		s.append('%i %i' % (x, y))
	print(a[0])
	for i in s:
		print(i)
for j in range(int(input())):
	start(int(input()))


from bisect import *
from collections import *
from math import *
from heapq import *
from typing import List
from itertools import *
from operator import *
from functools import *
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')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

@lru_cache(None)
def fact(x):
	if x < 2:
		return 1
	return fact(x - 1) * x

@lru_cache(None)
def per(i, j):
	return fact(i) // fact(i - j)

@lru_cache(None)
def com(i, j):
	return per(i, j) // fact(j)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 1
	res = 0
	for w in arr:
		res += w
		if res > x:
			res = w
		c += 1
	return c

def lowbit(n):
	return n & -n

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class smt:

	def __init__(self, l, r, arr):
		self.l = l
		self.r = r
		self.value = (1 << 31) - 1 if l < r else arr[l]
		mid = (l + r) // 2
		if l < r:
			self.left = smt(l, mid, arr)
			self.right = smt(mid + 1, r, arr)
			self.value &= self.left.value & self.right.value

	def setvalue(self, x, val):
		if self.l == self.r:
			self.value = val
			return
		mid = (self.l + self.r) // 2
		if x <= mid:
			self.left.setvalue(x, val)
		else:
			self.right.setvalue(x, val)
		self.value = self.left.value & self.right.value

	def ask(self, l, r):
		if l <= self.l and r >= self.r:
			return self.value
		val = (1 << 31) - 1
		mid = (self.l + self.r) // 2
		if l <= mid:
			val &= self.left.ask(l, r)
		if r > mid:
			val &= self.right.ask(l, r)
		return val

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d
t = N()
for i in range(t):
	n = N()
	heap = list(range(-n, 0, 1))
	arr = []
	while len(heap) > 1:
		a = heappop(heap)
		b = heappop(heap)
		tmp = ceil(-(a + b) / 2)
		heappush(heap, -tmp)
		arr.append((-a, -b))
	ans = -heap[0]
	print(ans)
	for (x, y) in arr:
		print(x, y)


import sys, io, os, time
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
for ii in range(int(input())):
	n = int(input())
	arr = [i for i in range(1, n + 1)]
	ans = []
	while len(arr) > 1:
		l = arr.pop()
		r = arr.pop()
		ans.append([l, r])
		arr.append((l + r + 1) // 2)
	print(arr[0])
	for i in ans:
		print(*i)


import sys
import math
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	n = int(input())
	print(2)
	for i in range(n, 1, -1):
		print(i - 1, n)
		n = n + i >> 1


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
for _ in range(int(input())):
	q = int(input())
	print(2)
	if q > 2:
		print(q, q - 2)
		print(q - 1, q - 1)
		for i in range(q - 3):
			print(q - 1 - i, q - 3 - i)
	else:
		print(1, 2)


import sys
t = int(sys.stdin.readline().strip())
for j in range(t):
	n = int(sys.stdin.readline().strip())
	a = []
	ans = n
	for i in range(n - 1, 0, -1):
		a.append([ans, i])
		ans = (ans + i + 1) // 2
	print(ans)
	for i in a:
		print('%s %s' % (i[0], i[1]))


test = int(input())
for _ in range(test):
	n = int(input())
	print(2)
	print(n, n - 1)
	for i in range(n, 2, -1):
		print(i, i - 2)


for _ in range(int(input())):
	n = int(input())
	print('2')
	print(n, n - 1)
	for i in range(0, n - 2):
		print(n - i, n - i - 2)


import sys
input = lambda : sys.stdin.readline().rstrip()
from collections import deque
from queue import LifoQueue

def binary_search(a, n):
	L = 0
	R = len(a) - 1
	while L <= R:
		mid = L + (R - L) // 2
		if a[mid] == n:
			return mid
		elif a[mid] < n:
			L = mid + 1
		else:
			R = mid - 1
	return -1
for _ in range(int(input())):
	n = int(input())
	print(2)
	if n > 2:
		print(n, n - 2)
		print(n - 1, n - 1)
		n -= 1
		while n > 2:
			print(n, n - 2)
			n -= 1
	else:
		print(1, 2)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in range(n, 0, -1)]
	b = []
	for i in range(n - 1):
		b.append([a[i], a[i + 1]])
		if (a[i] + a[i + 1]) % 2 != 0:
			a[i + 1] = (a[i] + a[i + 1] + 1) // 2
		else:
			a[i + 1] = (a[i] + a[i + 1]) // 2
	print(a[n - 1])
	for i in range(n - 1):
		print(*b[i])


import math
b = []
for i in range(int(input())):
	m = int(input())
	a = (m + (m - 1)) / 2
	print(2)
	print(m, m - 1)
	for t in range(m - 2, 0, -1):
		print(int(math.ceil(a)), t)
		a = (math.ceil(a) + t) / 2


from math import ceil
for _ in range(int(input())):
	n = int(input())
	a = [i for i in range(n, 0, -1)]
	print(2)
	(t_1, t) = (a[0], a[1])
	print(t_1, t)
	t_1 = ceil((t_1 + t) / 2)
	for j in range(2, n):
		t = a[j]
		print(t_1, t)
		t_1 = ceil((t_1 + t) / 2)


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')
import math
for j in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	else:
		vals = list(range(1, n + 1))
		ops = [(n, n - 2), (n - 1, n - 1)]
		count = n - 3
		cur = n - 1
		while count > 0:
			ops.append((cur, cur - 2))
			cur -= 1
			count -= 1
		print(cur)
		for i in ops:
			print(*i)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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:
			self.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')
import time
start_time = time.time()
import collections as col
import math
from functools import reduce

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def solve():
	N = getInt()
	A = [-(j + 1) for j in range(N)]
	h.heapify(A)
	ans = []
	while len(A) > 1:
		x = -h.heappop(A)
		y = -h.heappop(A)
		m = (x + y) // 2
		if (x + y) % 2 == 1:
			m += 1
		h.heappush(A, -m)
		ans.append((x, y))
	print(-A[0])
	for (x, y) in ans:
		print(x, y)
	return
for _ in range(getInt()):
	solve()


n = int(input())
for t in range(n):
	no = int(input())
	print(2)
	(x, y) = (no, no - 1)
	for i in range(1, no):
		print(x, y)
		(x, y) = ((x + y + 1) // 2, y - 1)


import sys
import math
import random
input = sys.stdin.readline
T = int(input())

def simulate(numbers):
	assert isinstance(numbers, list)
	while len(numbers) > 1:
		(x, y) = random.sample(numbers, 2)
		numbers.remove(x)
		numbers.remove(y)
		z = math.ceil((x + y) / 2)
		numbers.append(z)
		print('%d + %d = %d' % (x, y, z), (x + y) % 2)
	print('Finish ', next(iter(numbers)))
for t in range(T):
	N = int(input())
	result = N
	print(2)
	for j in range(N - 1, 0, -1):
		new_result = math.ceil((result + j) / 2)
		print(result, j)
		result = new_result


t = int(input())
for i in range(t):
	n = int(input())
	print(2)
	if n == 2:
		print(str(1) + ' ' + str(2))
	else:
		print(str(n - 2) + ' ' + str(n))
		print(str(n - 1) + ' ' + str(n - 1))
		for j in range(n - 3, 0, -1):
			print(j + 2, end=' ')
			print(j)


for test in range(int(input())):
	n = int(input())
	print(2)
	if n == 2:
		print('1 2')
	else:
		print(str(n) + ' ' + str(n - 2))
		print(str(n - 1) + ' ' + str(n - 1))
		if n > 3:
			for i in range(1, n - 2):
				print(str(n - i) + ' ' + str(n - i - 2))


import math

def solve():
	n = int(input())
	print(2)
	print(n - 1, n)
	r = n
	ind = n - 2
	for i in range(n - 2):
		print(ind, r)
		r = math.ceil((r + ind) / 2)
		ind -= 1
for _ in range(int(input())):
	solve()


import io
import os
from collections import Counter, defaultdict, deque

def solve(N):
	A = list(range(1, N + 1))[::-1]
	ops = []
	res = A[0]
	for x in A[1:]:
		ops.append((res, x))
		res = (res + x + 1) // 2
	return str(res) + '\n' + '\n'.join((str(x) + ' ' + str(y) for (x, y) in ops))
DEBUG = False
if DEBUG:
	import random
	random.seed(0)
	for N in range(1, 10):
		best = float('inf')
		for i in range(10000):
			A = list(range(1, N + 1))
			random.shuffle(A)
			best = min(best, res)
			if res == 2:
				print(A)
				break
		print(N, best)
	exit()
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N,) = [int(x) for x in input().split()]
	ans = solve(N)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	print(2)
	(a, b) = (n, n - 1)
	for i in range(1, n):
		print(a, b)
		(a, b) = ((a + b + 1) // 2, b - 1)


import math
import time
from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import PriorityQueue
import sys
from heapq import heapify, heappush, heappop
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	heap = [-i for i in range(1, n + 1)]
	heapify(heap)
	moves = []
	for _ in range(n - 1):
		x = heappop(heap)
		y = heappop(heap)
		moves.append([-x, -y])
		heappush(heap, (x + y) // 2)
	print(-1 * heappop(heap))
	for i in moves:
		print(*i)


a = int(input())
for i in range(a):
	b = int(input())
	print(2)
	if b == 2:
		print(1, 2)
	elif b == 3:
		print(1, 3)
		print(2, 2)
	else:
		print(b, b - 2)
		print(b - 1, b - 1)
		for i in range(b - 3, 0, -1):
			print(i, i + 2)


a = int(input())
for i in range(a):
	b = int(input())
	c = b
	d = b - 2
	print(2)
	print(b, b - 1)
	for x in range(b - 2):
		print(c, d)
		c = c - 1
		d = d - 1


def solve():
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
		return
	e = n
	s = n - 2
	print(2)
	print(s, e)
	print(s + 1, s + 1)
	while s > 0:
		e = s + 1
		s = e - 2
		if s > 0:
			print(s, e)
t = int(input())
for _ in range(t):
	solve()


from math import ceil
for _ in range(int(input())):
	n = int(input())
	if n == 1:
		print(1)
	elif n == 2:
		print(2)
		print(1, 2)
	else:
		i = 2
		print(2)
		rem = ceil((n + n - 1) / 2)
		print(n, n - 1)
		while i < n:
			print(rem, n - i)
			i += 1
			rem = ceil((rem + n - i) / 2)


import sys
t = int(input())

def answer(n):
	if n == 2:
		print(2)
		print(1, 2)
	elif n % 2 == 0:
		print(2)
		print(n - 2, n)
		print(n - 1, n - 1)
		for i in range(n - 3):
			print(n - 1 - i, n - 3 - i)
	elif n % 2 == 1:
		print(2)
		print(n - 2, n)
		print(n - 1, n - 1)
		for i in range(n - 3):
			print(n - 1 - i, n - 3 - i)
for i in range(t):
	n = int(input())
	answer(n)


def solve(n):
	steps = []
	if n == 2:
		return (2, [(1, 2)])
	arr = [i for i in range(1, n + 1)]
	steps.append((arr[-1], arr[-3]))
	arr[-3] = int((arr[-1] + arr[-3]) / 2)
	del arr[-1]
	steps.append((arr[-1], arr[-2]))
	del arr[-1]
	for _ in range(n - 1 - 2):
		steps.append((arr[-1], arr[-2]))
		arr[-2] = int((arr[-1] + arr[-2]) / 2)
		del arr[-1]
	return (2, steps)
t = int(input())
for _ in range(t):
	n = int(input())
	(a, steps) = solve(n)
	print(a)
	for (x, y) in steps:
		print(x, y)


t = int(input())
for you in range(t):
	n = int(input())
	print(2)
	l = [i + 1 for i in range(n)]
	for i in range(n - 1):
		print(l[-1], l[-2])
		z = (l[-1] + l[-2] + 1) // 2
		l.pop(-1)
		l.pop(-1)
		l.append(z)


import math
t = int(input())
for i in range(t):
	n = int(input())
	print(2)
	old = n
	for l in reversed(range(1, n)):
		print(old, l)
		old = math.ceil((old + l) / 2)


from math import ceil
t = int(input())
for _ in range(t):
	n = int(input())
	values = list(range(1, n + 1))
	pairs = []
	for i in range(n - 2, 0, -1):
		pairs.append('{} {}'.format(values[i + 1], values[i]))
		values[i] = ceil((values[i] + values[i + 1]) / 2)
	pairs.append('{} {}'.format(values[0], values[1]))
	print(ceil((values[0] + values[1]) / 2))
	print('\n'.join(pairs))


import math
n = int(input())
for i in range(n):
	a = int(input())
	print(2)
	rs = a
	for i in range(a - 1, 0, -1):
		print(rs, i)
		rs = math.ceil((rs + i) / 2)


for _ in range(int(input())):
	n = int(input())
	print(2)
	l = list()
	for i in range(n):
		l.append(i + 1)
	for i in range(n - 1):
		a = l.pop()
		b = l.pop()
		print(a, b)
		add = a + b
		if add & 1:
			add = add // 2 + 1
		else:
			add = add // 2
		l.append(add)


for i in range(int(input())):
	n = int(input())
	arr = [i for i in range(1, n + 1)]
	ans = []
	while len(arr) != 2:
		a = arr.pop()
		if a % 2 == 0 and arr[-1] % 2 == 0 or (a % 2 != 0 and arr[-1] % 2 != 0):
			d = -1
		else:
			d = -2
		ans.append([a, arr[d]])
		e = arr[d]
		arr.pop(d)
		arr.append((a + e) // 2)
	ans.append(arr)
	print(round(sum(arr) / 2))
	for j in ans:
		print(j[0], j[1])


def whiteboard(n):
	if n == 2:
		print(2)
		print(1, 2)
		return
	print(2)
	print(n, n - 2)
	print(n - 1, n - 1)
	for i in range(n - 1, 2, -1):
		print(i, i - 2)
	return
for t in range(int(input())):
	n = int(input())
	whiteboard(n)


t = int(input())
for i in range(t):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
		continue
	print(n - 2, n)
	print(n - 1, n - 1)
	res = n - 1
	for i in range(n - 3, 0, -1):
		print(i, res)
		res = (res + i) // 2


def process(n):
	x = list(range(1, n + 1))
	numbers = []
	while len(x) > 1:
		if len(x) == 2:
			numbers.append([x[0], x[1]])
			mean = (x[0] + x[1] + 1) // 2
			del x[1]
			del x[0]
			x.append(mean)
		elif (x[-1] + x[-2]) % 2 == 1:
			numbers.append([x[-3], x[-1]])
			mean = (x[-3] + x[-1] + 1) // 2
			del x[-1]
			del x[-2]
			x.append(mean)
		else:
			numbers.append([x[-2], x[-1]])
			mean = (x[-2] + x[-1] + 1) // 2
			del x[-1]
			del x[-1]
			x.append(mean)
	print(x[0])
	for nn in numbers:
		print(' '.join(map(str, nn)))
n = int(input())
for t in range(n):
	m = int(input())
	process(m)


import sys
import math
for i in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
		continue
	v = []
	st = []
	for i in range(1, n + 1):
		st.append(i)
	first = st.pop()
	temp = st.pop()
	second = st.pop()
	tempo = math.ceil((first + second) / 2)
	st.append(tempo)
	st.append(temp)
	v.append([second, first])
	for i in range(1, n - 1):
		if len(st) <= 2:
			break
		first = st.pop()
		second = st.pop()
		v.append([second, first])
		tempo = math.ceil((first + second) / 2)
		st.append(tempo)
	first = st.pop()
	second = st.pop()
	print(math.ceil((first + second) / 2))
	v.append([second, first])
	for i in v:
		print(i[0], i[1])


testcases = int(input())
for _ in range(testcases):
	n = int(input())
	l = [i for i in range(1, n + 1)]
	print(2)
	for i in range(n - 1):
		(temp1, temp2) = (l[-1], l[-2])
		temp3 = (temp1 + temp2 + 1) // 2
		print(temp1, temp2)
		del l[-1]
		l[-1] = temp3


for _ in range(int(input())):
	n = int(input())
	print(2)
	l = n
	m = n - 1
	for _ in range(n - 1):
		print(l, m)
		l = (l + m + 1) // 2
		m -= 1


from math import ceil
for _ in range(int(input())):
	n = int(input())
	l = [i for i in range(1, n + 1)]
	lst = []
	while len(l) != 1:
		a = l.pop()
		b = l.pop()
		l.append(ceil((a + b) / 2))
		lst.append([a, b])
	print(*l)
	for i in lst:
		print(*i)


import math
for _ in range(int(input())):
	n = int(input())
	a = []
	summ = n
	i = n - 1
	while i > 0:
		a.append([summ, i])
		summ = math.ceil((summ + i) / 2)
		i -= 1
	print(summ)
	for i in a:
		(x, y) = i
		print(x, y)


import math
t = int(input())
while t:
	t -= 1
	n = int(input())
	if n == 1:
		print(1)
		continue
	print(2)
	num2 = n - 1
	num1 = n
	for i in range(n - 1):
		print(num1, num2)
		num1 = math.ceil((num1 + num2) / 2)
		num2 -= 1


for t in range(int(input())):
	n = int(input())
	a = [[n, n - 1]]
	i = n - 1
	while i != 1:
		a.append([(a[-1][0] + a[-1][1] + 1) // 2, i - 1])
		i -= 1
	print((a[-1][0] + a[-1][1] + 1) // 2)
	for i in range(n - 1):
		print(a[i][0], a[i][1])


import sys, math
import heapq
r = sys.stdin.readline

def midAB(a, b):
	return math.ceil((a + b) / 2)
for _ in range(int(r())):
	n = int(r())
	lst = list(range(1, n + 1))
	history = []
	if n == 2:
		print(midAB(1, 2))
		print('1 2')
	else:
		a = lst.pop(-3)
		b = lst.pop(-1)
		lst.append(midAB(a, b))
		history.append((a, b))
		while len(lst) != 1:
			a = lst.pop()
			b = lst.pop()
			lst.append(midAB(a, b))
			history.append((a, b))
		print(lst[0])
		for (a, b) in history:
			print(a, b)


import sys

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

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n = mint()
	a = list(range(1, n + 1))
	act = []
	while len(a) > 1:
		x = a[-1]
		if len(a) > 2 and a[-2] == x - 1 and (a[-3] == x - 2):
			act.append((x - 2, x))
			act.append((x - 1, x - 1))
			a.pop()
			a.pop()
			a.pop()
			a.append(x - 1)
		else:
			y = (x + a[-2] + 1) // 2
			act.append((x, a[-2]))
			a.pop()
			a.pop()
			a.append(y)
	print(a[0])
	for (x, y) in act:
		print(x, y)
for i in range(mint()):
	solve()


n = input()
for x in range(int(n)):
	entrada = int(input())
	print(2)
	if entrada == 2:
		print('2 1')
	else:
		print(str(entrada) + ' ' + str(entrada - 2))
		print(str(entrada - 1) + ' ' + str(entrada - 1))
		i = entrada - 1
		while i > 2:
			print(str(i) + ' ' + str(i - 2))
			i = i - 1


t = int(input())
for i in range(t):
	n = int(input())
	print(2)
	now = n
	for i in range(n - 1, 0, -1):
		print(i, now)
		now = (i + now + 1) // 2


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


import sys, io, os
BUFSIZE = 8192

class FastIO(io.IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = io.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(io.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()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
T = int(input())
for _ in range(T):
	N = int(input())
	L = list(range(1, N + 1))
	Ans = []
	for _ in range(N - 1):
		a = L.pop()
		b = L.pop()
		L.append(a + b + 1 >> 1)
		Ans.append((a, b))
	print(L[0])
	for (a, b) in Ans:
		print(a, b)


from math import ceil

def void():
	(a, b) = (2, 3)
	return a * b
t = int(input())
for _ in range(t):
	n = int(input())
	l = [0] * n
	for i in range(n):
		l[i] = i + 1
	temp = []
	while len(l) != 1:
		a = l.pop()
		b = l.pop()
		d = ceil((a + b) / 2)
		l.append(d)
		temp.append([a, b])
	print(*l)
	for t in temp:
		print(*t)


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
for _ in range(inp()):
	n = inp()
	prev = n
	print(2)
	for i in range(n - 1, 0, -1):
		print(i, prev)
		prev = (i + prev - 1) // 2 + 1


import math
for _ in range(int(input())):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
	else:
		print(n - 2, n)
		print(n - 1, n - 1)
		for i in range(n - 3, 0, -1):
			print(i, i + 2)


t = int(input())
cases = []
for i in range(t):
	cases.append(int(input()))
for n in cases:
	print('2')
	if n == 2:
		print('1 2')
		continue
	temp = n
	for i in range(n - 1, 0, -1):
		print(str(temp) + ' ' + str(i))
		temp = (temp + i + 1) // 2


import heapq

def minNum(n):
	nums = [-i for i in range(1, n + 1)]
	heapq.heapify(nums)
	moves = []
	while len(nums) > 1:
		a = -int(heapq.heappop(nums))
		b = -int(heapq.heappop(nums))
		if (a + b) % 2 == 0:
			heapq.heappush(nums, -(a + b) / 2)
		else:
			heapq.heappush(nums, -(a + b + 1) / 2)
		moves.append((a, b))
	print(-int(nums[0]))
	for mov in moves:
		print(*mov)
	return
t = int(input())
for i in range(t):
	n = int(input())
	minNum(n)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	n = ip()
	ans = []
	stack = [i for i in range(1, n + 1)]
	while len(stack) != 1:
		a = stack.pop()
		b = stack.pop()
		stack.append(ceil((a + b) / 2))
		ans.append('{} {}'.format(a, b))
	out(stack[0])
	for i in ans:
		out(i)


def solve():
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
		return 0
	lst = list(range(1, n + 1))
	ans = []
	ans.append([n - 2, n])
	ans.append([n - 1, n - 1])
	lst.pop()
	lst.pop()
	lst.pop()
	lst.append(n - 1)
	while len(lst) > 1:
		a = lst[-1]
		b = lst[-2]
		c = (a + b + 1) // 2
		ans.append([a, b])
		lst.pop()
		lst.pop()
		lst.append(c)
	print(lst[0])
	for i in ans:
		print(*i)
for i in range(int(input())):
	solve()


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi
import math
from itertools import permutations
from copy import deepcopy

def main():
	for t in range(int(input())):
		n = int(input())
		print(2)
		if n == 2:
			print(1, 2)
		else:
			(j, i) = (n, n - 2)
			print(i, j)
			print((i + j) // 2, (i + j) // 2)
			j = (i + j) // 2
			(i, k) = (j - 2, n - 3)
			while k > 0:
				print(i, j)
				j = (i + j) // 2
				i = j - 2
				k -= 1
				if i == 1:
					print(1, 3)
					k -= 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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def dfs(lst):
	if lst == 0:
		print(0)
	if lst == 1:
		print(1)
	else:
		print(2)
		if lst == 2:
			print(1, 2)
		else:
			print(lst - 1, lst)
			for i in range(lst - 1, 1, -1):
				print(i - 1, i + 1)
tc = int(input())
for _ in range(tc):
	case = int(input())
	dfs(case)


from math import ceil
from collections import deque
for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n + 1):
		a.append(i)
	print(2)
	for i in range(n, 1, -1):
		print(a[i - 1], a[i])
		a[i - 1] = ceil((a[i] + a[i - 1]) / 2)


import bisect
import math
for t in range(int(input())):
	n = int(input())
	arr = []
	for i in range(1, n + 1):
		arr.append(i)
	ans = []
	while len(arr) > 1:
		a = arr.pop(-1)
		if arr[-1] == a:
			ans.append([a, a])
			continue
		if (a + arr[-1]) % 2 == 0:
			ans.append([a, arr[-1]])
			add = math.ceil((a + arr[-1]) / 2)
			arr.pop(-1)
			bisect.insort(arr, add)
		elif len(arr) >= 2:
			ans.append([a, arr[-2]])
			add = math.ceil((a + arr[-2]) / 2)
			arr.pop(-2)
			bisect.insort(arr, add)
		else:
			ans.append([a, arr[-1]])
			add = math.ceil((a + arr[-1]) / 2)
			arr.pop(-1)
			bisect.insort(arr, add)
	print(*arr)
	for i in ans:
		print(*i)


from bisect import *
from math import *
from collections import Counter, defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))

def solve():
	n = I()
	ans = n
	print(2)
	for i in range(n - 1, 0, -1):
		print(ans, i)
		ans += i
		if ans % 2:
			ans = ans // 2 + 1
		else:
			ans //= 2
for _ in range(I()):
	solve()


from math import ceil
for _ in range(int(input())):
	n = int(input())
	k = [i for i in range(1, n + 1)]
	print(2)
	for i in range(n - 1):
		a = k.pop()
		b = k.pop()
		k.append(ceil((a + b) / 2))
		print(a, b)


for ik in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	elif n == 3:
		print(2)
		print(1, 3)
		print(2, 2)
	else:
		print(2)
		print(n, n - 2)
		print(n - 1, n - 1)
		t = 0
		for i in range(n - 3, 0, -1):
			print(i, n - 1 - t)
			t += 1


for _ in range(int(input())):
	n = int(input())
	print(2)
	k = n
	for i in range(n - 1):
		print(n - 1 - i, k)
		k = (k + n - i) // 2


from math import gcd
from bisect import bisect_left, bisect_right
from itertools import combinations
from itertools import permutations
from bisect import bisect_left
from math import ceil
from math import radians
from heapq import heapify, heappush, heappop, nsmallest
import bisect
from math import pi
from collections import deque
from math import factorial
from math import log, ceil
from collections import defaultdict
from math import *
from sys import stdin, stdout
import itertools
import os
import sys
import threading
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import *
from fractions import Fraction
mod = int(pow(10, 9) + 7)

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

def si():
	return str(input())

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

def li1():
	return list(mi())

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

def fsi():
	return str(stdin.readline())

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

def fli():
	return list(fmi())
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

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

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d:
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d:
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = defaultdict(list)
	for i in range(n):
		(x, y) = mi()
		d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0 and i % 2 == 1:
			s.add(i)
			n = n // i
	if n > 2 and n % 2 == 1:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)

def SieveOfEratosthenes(n, isPrime):
	isPrime[0] = isPrime[1] = False
	for i in range(2, n):
		isPrime[i] = True
	p = 2
	while p * p <= n:
		if isPrime[p] == True:
			i = p * p
			while i <= n:
				isPrime[i] = False
				i += p
		p += 1
	return isPrime

def dijkstra(edges, f, t):
	g = defaultdict(list)
	for (l, r, c) in edges:
		g[l].append((c, r))
	(q, seen, mins) = ([(0, f, ())], set(), {f: 0})
	while q:
		(cost, v1, path) = heappop(q)
		if v1 not in seen:
			seen.add(v1)
			path = (v1, path)
			if v1 == t:
				return (cost, path)
			for (c, v2) in g.get(v1, ()):
				if v2 in seen:
					continue
				prev = mins.get(v2, None)
				next = cost + c
				if prev is None or next < prev:
					mins[v2] = next
					heappush(q, (next, v2, path))
	return float('inf')

def binsearch(a, l, r, x):
	while l <= r:
		mid = l + (r - 1) // 2
		if a[mid]:
			return mid
		elif a[mid] > x:
			l = mid - 1
		else:
			r = mid + 1
	return -1

def readTree(n):
	adj = [set() for _ in range(n)]
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		adj[u - 1].add(v - 1)
		adj[v - 1].add(u - 1)
	return adj

def treeOrderByDepth(n, adj, root=0):
	parent = [-2] + [-1] * (n - 1)
	ordered = []
	q = deque()
	q.append(root)
	depth = [0] * n
	while q:
		c = q.popleft()
		ordered.append(c)
		for a in adj[c]:
			if parent[a] == -1:
				parent[a] = c
				depth[a] = depth[c] + 1
				q.append(a)
	return (ordered, parent, depth)

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def nextPowerOf2(n):
	count = 0
	if n and (not n & n - 1):
		return n
	while n != 0:
		n >>= 1
		count += 1
	return 1 << count

def cou(n):
	c = 0
	while n > 1:
		c += 1
		n //= 2
	return c

def sortsec(l):
	return sorted(l, key=lambda x: x[1])

def BinarySearch(a, x):
	i = bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def subarray(A):
	r = set()
	p = {0}
	for x in A:
		p = {x | y for y in p} | {x}
		r |= p
	return len(r)

def setBitNumber(n):
	n |= n >> 1
	n |= n >> 2
	n |= n >> 4
	n |= n >> 8
	n |= n >> 16
	n = n + 1
	return n >> 1

def countSetBits(n):
	count = 0
	while n:
		count += n & 1
		n >>= 1
	return count
for _ in range(ii()):
	n = ii()
	l = []
	a = n
	for i in range(n - 1, 0, -1):
		l.append([a, i])
		a += i
		if a % 2 == 0:
			a = a // 2
		else:
			a = a // 2 + 1
	print(a)
	for i in l:
		print(*i)


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, 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 = 998244353
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('a')

def solve():
	for _ in range(ii()):
		n = ii()
		print(2)
		print(n, n - 1)
		x = 2 * n // 2
		for i in range(n - 2, 0, -1):
			print(x, i)
			x = (x + i + 1) // 2
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
solve()


import math
for _ in range(int(input())):
	n = int(input())
	print(2)
	l = [i for i in range(1, n + 1)]
	avg = l[-1]
	while n > 1:
		print(avg, n - 1)
		avg = math.ceil((avg + n - 1) / 2)
		n -= 1


from sys import stdin
import math, collections, heapq, functools

def ip():
	return [int(i) for i in stdin.readline().split()]

def sp():
	return [str(i) for i in stdin.readline().split()]

def solve(n):
	A = [-i for i in range(1, n + 1)]
	heapq.heapify(A)
	ans = []
	while len(A) > 1:
		(x, y) = (-1 * heapq.heappop(A), -1 * heapq.heappop(A))
		ans.append([x, y])
		heapq.heappush(A, -1 * math.ceil((x + y) / 2))
	print(-1 * A[0])
	for (i, j) in ans:
		print(i, j)
t = int(input())
for _ in range(t):
	n = int(input())
	solve(n)


from math import ceil
for jai_Shree_RAM in range(int(input())):
	n = int(input())
	print(2)
	l = n
	while n > 1:
		n -= 1
		print('{} {}'.format(l, n))
		l = ceil((l + n) / 2)


l = []
for _ in range(int(input())):
	n = int(input())
	t = [i + 1 for i in range(n)]
	a = 1
	sum = 0
	s = []
	for i in range(n - 1, 1, -1):
		if t[i - 1] % 2 == t[i] % 2:
			s.append(str(t[i - 1]) + ' ' + str(t[i]))
			t[i - 1] = (t[i - 1] + t[i]) // 2
		else:
			s.append(str(t[i]) + ' ' + str(t[i - 2]))
			t[i - 2] = (t[i] + t[i - 2]) // 2
	l.append((t[0] + t[1] + 1) // 2)
	for i in s:
		l.append(i)
	l.append(' '.join([str(t[0]), str(t[1])]))
for i in l:
	print(i)


import sys
import os
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')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	lst = []
	for i in range(n):
		temp = [default] * m
		lst.append(temp)
	return lst

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

def solve(n):
	print(2)
	print(n, n - 1)
	average = n
	for i in range(n - 2, 0, -1):
		print(int(average), i)
		average = (average + i) / 2
for _ in range(int(input())):
	n = int(input())
	solve(n)


t = int(input())
out = []
for _ in range(t):
	n = int(input())
	arr = [x for x in range(1, n + 1)]
	res = ['2', str(n) + ' ' + str(n - 1)]
	a = n
	b = n - 2
	for _ in range(n - 2):
		res.append(str(a) + ' ' + str(b))
		a = a - 1
		b = b - 1
	out.append(res)
for i in out:
	for j in i:
		print(j)


from math import ceil
t = int(input())
for i in range(t):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	else:
		first = n - 1
		last = n
		ans = [(first, last)]
		while first != 1:
			first -= 1
			ans.append((first, last))
			if first == 1:
				print((1 + last) // 2)
			last -= 1
		for j in ans:
			print(j[0], j[1])


from sys import stdin
import math
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	base = n
	print(2)
	while n != 1:
		print(base, n - 1)
		base = math.ceil((base + (n - 1)) / 2)
		n -= 1


T = int(input())
for I in range(0, T):
	N = int(input())
	print(2)
	X = N
	for J in range(1, N):
		print(X, N - J)
		X = (X + N - J) / 2
		if int(X) != X:
			X = int(X) + 1
		else:
			X = int(X)


a = int(input())
for i in range(a):
	n = int(input())
	print(2)
	c = [int(i) for i in range(1, n + 1)]
	r1 = c[-1]
	for i in range(n - 1):
		rrr = (c[-1] + c[-2] + 1) // 2
		print(c.pop(), c.pop())
		c.append(rrr)


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

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

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

def invr():
	return map(int, input().split())
n = inp()
for i in range(n):
	x = inp()
	l = list(range(x + 1))
	l = l[1:]
	even = []
	odd = []
	for j in range(1, x + 1):
		if j % 2 == 0:
			even.append(j)
		else:
			odd.append(j)
	steps = []
	turn = x % 2
	while len(even) + len(odd) > 1:
		if len(odd) == 1 and len(even) == 1:
			steps.append([even[-1], odd[-1]])
			even.pop(-1)
			odd.pop(-1)
		elif len(odd) > 1 and len(even) > 1:
			if even[-1] > odd[-1]:
				steps.append([even[-1], even[-2]])
				new_val = (even[-1] + even[-2]) // 2
				even.pop(-1)
				even.pop(-1)
				if new_val % 2 == 0:
					even.append(new_val)
				else:
					odd.append(new_val)
			else:
				steps.append([odd[-1], odd[-2]])
				new_val = (odd[-1] + odd[-2]) // 2
				odd.pop(-1)
				odd.pop(-1)
				if new_val % 2 == 0:
					even.append(new_val)
				else:
					odd.append(new_val)
				turn = 0
		elif len(even) >= 2:
			steps.append([even[-1], even[-2]])
			new_val = (even[-1] + even[-2]) // 2
			even.pop(-1)
			even.pop(-1)
			if new_val % 2 == 0:
				even.append(new_val)
			else:
				odd.append(new_val)
			turn = 1
		elif len(odd) >= 2:
			steps.append([odd[-1], odd[-2]])
			new_val = (odd[-1] + odd[-2]) // 2
			odd.pop(-1)
			odd.pop(-1)
			if new_val % 2 == 0:
				even.append(new_val)
			else:
				odd.append(new_val)
			turn = 0
	print((sum(steps[-1]) + 1) // 2)
	for step in steps:
		print(step[0], step[1])


import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
from math import ceil

def main():
	try:
		for _ in range(inp()):
			n = inp()
			print('2')
			a = [i for i in range(1, n + 1)]
			while len(a) > 1:
				one = a.pop()
				two = a.pop()
				print(one, two)
				a.append(ceil((one + two) / 2))
	except Exception as e:
		print(e)
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()


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	input = sys.stdin.buffer.readline
	for _ in range(int(input())):
		N = int(input())
		if N == 2:
			print(2)
			print(1, 2)
			continue
		print(2)
		print(N, N - 2)
		print(N - 1, N - 1)
		for i in range(N - 3, 0, -1):
			print(i, i + 2)
main()


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	n = int(z())
	print(2)
	print(n - 1, n)
	for i in range(n - 2):
		print(n - 2 - i, n - i)


import math
t = int(input())
for i in range(t):
	n = int(input())
	print(2)
	j = n
	last = n
	seclast = n - 1
	while j > 1:
		print(last, seclast)
		last = math.ceil((last + seclast) / 2)
		seclast -= 1
		j -= 1


import math
t = int(input())
for i in range(t):
	n = int(input())
	nums = [k for k in range(1, n + 1)]
	nums1 = []
	while len(nums) != 1:
		b = nums[-1]
		d = nums[-2]
		nums1.append('{0} {1}'.format(d, b))
		nums.pop()
		nums.pop()
		nums.append(math.ceil((b + d) / 2))
	print(nums[0])
	print('\n'.join(nums1))


T = int(input())
ans_times = [0] * T
ans_ls = []
for t in range(T):
	N = int(input())
	if N == 2:
		ans_ls.append([[1, 2]])
		ans_times[t] = 2
		continue
	ls = []
	ls.append([N, N - 2])
	ls.append([N - 1, N - 1])
	left = N - 1
	while left - 2 > 0:
		ls.append([left, left - 2])
		left -= 1
	ans_times[t] = sum(ls[-1]) // 2
	ans_ls.append(ls)
for t in range(T):
	print(ans_times[t])
	for ls in ans_ls[t]:
		print(*ls)


x = int(input())
for i in range(x):
	n = int(input())
	l = [t for t in range(1, n + 1)]
	j = n - 1
	h = []
	if len(l) == 2:
		x = int((l[0] + l[1]) / 2)
		print(2)
		print(l[0], l[1])
	else:
		while len(l) > 1:
			if l[j] % 2 == 0 and l[j - 1] % 2 == 0:
				l.append(int((l[j] + l[j - 1]) / 2))
				z = l.pop(j)
				y = l.pop(j - 1)
				j = j - 1
			elif l[j] % 2 == 0 and l[j - 2] % 2 == 0 and (l[j - 1] % 2 != 0):
				l.append(int((l[j] + l[j - 2]) / 2))
				z = l.pop(j)
				y = l.pop(j - 2)
				j = j - 1
			elif l[j] % 2 != 0 and l[j - 2] % 2 != 0 and (l[j - 1] % 2 == 0):
				l.append(int((l[j] + l[j - 2]) / 2))
				z = l.pop(j)
				y = l.pop(j - 2)
				j = j - 1
			elif l[j] % 2 != 0 and l[j - 1] % 2 != 0:
				l.append(int((l[j] + l[j - 1]) / 2))
				z = l.pop(j)
				y = l.pop(j - 1)
				j = j - 1
			h.append(y)
			h.append(z)
		print(l[0])
		for m in range(0, len(h), 2):
			print(h[m], h[m + 1])


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop, heapify
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
from itertools import accumulate
from functools import lru_cache
M = mod = 10 ** 9 + 7

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

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	n = val()
	print(2)
	l = list(range(1, n + 1))
	for i in range(n - 1):
		(a, b) = (l.pop(), l.pop())
		print(a, b)
		l.append((a + b + 1) // 2)


import os
import heapq
import sys, threading
import math
import operator
from collections import defaultdict, deque
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

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

def pw(a, b, md):
	result = 1
	while b > 0:
		if b % 2 == 1:
			result *= a
			result %= md
		a *= a
		a %= md
		b //= 2
	return result % md

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		n = int(input())
		q = deque()
		for i in range(1, n + 1):
			q.append(i)
		print(2)
		while len(q) > 1:
			print(q[-1], q[-2])
			a = q.pop()
			b = q.pop()
			val = int(math.ceil((a + b) / 2))
			q.append(val)
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')
threading.Thread(target=main).start()


t = int(input())

def result(n):
	llist = [int(x) for x in range(1, n + 1)]
	print(2)
	for i in range(n - 1, 0, -1):
		print(llist[i], llist[i - 1])
		llist[i - 1] = (llist[i - 1] + llist[i] + 1) // 2
for i in range(t):
	n = int(input())
	result(n)


from sys import stdin, stdout
input = stdin.readline
print = lambda x: stdout.write(str(x) + '\n')
for _ in range(int(input())):
	n = int(input())
	a = list(range(1, n + 1))
	ans = []
	while len(a) != 1:
		ans.append('{0} {1}'.format(a[-1], a[-2]))
		avg = (a.pop() + a.pop() + 1) // 2
		a.append(avg)
	print(2)
	print('\n'.join(ans))


for _ in range(int(input())):
	n = int(input())
	ans = []
	current = n
	for i in range(n - 1):
		ans.append((current, n - 1 - i))
		current = (current + n - i) // 2
	print(current)
	for i in range(n - 1):
		print(ans[i][0], ans[i][1])


import sys
input = sys.stdin.buffer.readline

def solution():
	n = int(input())
	ans = n
	prev = n
	l = [[n, n - 1]]
	for i in range(n - 2, 0, -1):
		x = prev + i - 1
		if x % 2 != 0:
			x += 1
		l.append([prev, i])
		prev = x // 2
	print(prev)
	for i in range(len(l)):
		print(l[i][0], l[i][1])
t = int(input())
for _ in range(t):
	solution()


import sys
import math
for _ in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
		continue
	arr = list(range(1, n + 1))
	res = []
	a = arr[n - 1]
	b = arr[n - 3]
	del arr[n - 1]
	del arr[n - 3]
	res.append((a, b))
	arr.append((a + b) // 2)
	while len(arr) > 1:
		l = len(arr)
		a = arr[l - 1]
		b = arr[l - 2]
		del arr[l - 1]
		del arr[l - 2]
		res.append((a, b))
		arr.append((a + b) // 2)
	print(arr[0])
	for i in range(len(res)):
		print(*res[i])


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

def mi():
	return map(int, input().split())
for _ in range(ii()):
	n = ii()
	if n == 2:
		print('2\n2 1')
		continue
	l = list(range(1, n + 1))
	a = l.pop()
	answer = []
	b = l.pop(-2)
	answer.append((a, b))
	a = int((a + b) / 2)
	while l:
		b = l.pop()
		answer.append((a, b))
		a = int((a + b) / 2)
	print(a)
	for i in answer:
		print(*i)


for _ in range(int(input())):
	n = int(input())
	k = n
	print(2)
	for i in range(n - 1, 0, -1):
		print(i, k)
		if (k + i) % 2 != 0:
			k = (k + i) // 2 + 1
		else:
			k = (k + i) // 2


def ans(x):
	print(2)
	spisok = list(range(1, x + 1))
	while len(spisok) > 1:
		s1 = spisok.pop()
		s2 = spisok.pop()
		spisok.append((s1 + s2 + (s2 + s1) % 2) // 2)
		print(s1, s2)
t = int(input())
for i in range(t):
	ans(int(input()))


t = int(input())
for i in range(t):
	print(2)
	n = int(input())
	lista = list(range(1, n + 1))
	for j in range(n - 1):
		print(lista[-1], lista[-2])
		if (lista[-1] + lista[-2]) % 2 == 1:
			novo = (lista[-1] + lista[-2] + 1) // 2
			lista[-2] = novo
			lista.pop()
		else:
			novo = (lista[-1] + lista[-2]) // 2
			lista[-2] = novo
			lista.pop()


for i in range(int(input())):
	a1 = []
	n = int(input())
	lst = [i for i in range(1, n + 1)]
	lst = lst[::-1]
	if n == 2:
		print(2)
		print(1, 2)
	else:
		x1 = lst[0] + lst[1]
		x = x1 // 2
		if x1 % 2 != 0:
			x += 1
		a1.append([lst[0], lst[1]])
		for i in range(2, len(lst)):
			x1 = x + lst[i]
			a1.append([x, lst[i]])
			x = x1 // 2
			if x1 % 2 != 0:
				x += 1
		print(x)
		for i in a1:
			print(*i)


for _ in range(int(input())):
	a = int(input())
	print(2)
	print(a - 1, a)
	for i in range(a - 2, 0, -1):
		print(i, i + 2)


from collections import deque, defaultdict
from heapq import heapify, heappop
t = int(input())
for _ in range(t):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
		continue
	print(n, n - 2)
	print(n - 1, n - 1)
	(a, b) = (n - 3, n - 1)
	for _ in range(n - 3):
		print(a, b)
		(a, b) = (a - 1, b - 1)


from sys import stdin, stdout
import math
import heapq
import collections
input = stdin.readline

def inputnum():
	return int(input())

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

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

def inputstring():
	return [x for x in input()]

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

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	n = inputnum()
	print(2)
	cur = n
	for i in reversed(range(1, n)):
		print(cur, i)
		if cur % 2 == i % 2:
			cur = (cur + i) // 2
		else:
			cur = (cur + i) // 2 + 1


def solve(n):
	print(2)
	print(n - 1, n)
	for i in range(n - 2):
		print(n - i - 2, n - i)
s = int(input())
for i in range(s):
	n = int(input())
	solve(n)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) + 1 for i in range(n)]
	print(2)
	print(a[len(a) - 1], a[len(a) - 2])
	i = len(a) - 1
	while i != 1:
		print(a[i], a[i - 2])
		i -= 1


for _ in range(int(input())):
	n = int(input())
	order = []
	nums = list(range(1, n + 1))
	print(2)
	if n == 2:
		print(1, 2)
	else:
		i = 0
		while i != n - 1:
			one = nums.pop()
			if i == 0:
				two = nums.pop(-2)
			else:
				two = nums.pop()
			order.append([two, one])
			nums.append((one + two) // 2)
			i += 1
	for (start, stop) in order:
		print(start, stop)


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	print('2')
	i = n
	if n == 2:
		print('{} {}'.format(1, 2))
	while n > 2:
		print('{} {}'.format(n - 2, n))
		if n == i:
			print('{} {}'.format((n - 2 + n) // 2, (n - 2 + n) // 2))
		n = n - 1


TC = int(input())
for tc in range(TC):
	N = int(input())
	if N == 2:
		print(2)
		print('1 2')
		continue
	t = N
	print(2)
	print(t, t - 2)
	print(t - 1, t - 1)
	t -= 1
	for i in range(N - 3):
		print(t, t - 2)
		t -= 1


import math
t = int(input())
for tt in range(0, t):
	n = int(input())
	print(2)
	cur = n
	for i in range(n, 1, -1):
		print(i - 1, cur, sep=' ')
		cur = math.floor((cur + i) / 2)


t = int(input())
for i in range(t):
	n = int(input())
	if n == 2:
		print(2)
		print(2, 1)
	elif n == 3:
		print(2)
		print(3, 1)
		print(2, 2)
	else:
		print(2)
		(x, y) = (n - 2, n)
		print(x, y)
		(x, y) = (n - 1, n - 1)
		print(x, y)
		(x, y) = (n - 3, n - 1)
		print(x, y)
		while x > 1:
			(x, y) = (x - 1, y - 1)
			print(x, y)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	for i in range(n):
		a.append(i + 1)
	print(2)
	i = n - 1
	while i > 0:
		print(str(a[i]) + ' ' + str(a[i - 1]))
		a[i - 1] = math.ceil((a[i] + a[i - 1]) / 2)
		i -= 1
	print()


from sys import stdin
from math import ceil
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	print(2)
	if n == 2:
		print(2, 1)
	else:
		print(n, n - 2)
		print(n - 1, n - 1)
		for i in range(n - 1, 2, -1):
			print(i, i - 2)


for i in range(int(input())):
	n = int(input())
	z = n
	l1 = []
	l2 = []
	ind1 = 3
	for i in range(n - 2):
		if i < n - 1 - 3:
			l1.append(ind1)
		else:
			l1.append(n - 1)
		ind1 += 1
	l1.append(n)
	ind1 = 1
	for i in range(n - 3):
		l2.append(ind1)
		ind1 += 1
	l2.append(n - 1)
	l2.append(n - 2)
	print(2)
	for i in range(z - 2, -1, -1):
		print(l1[i], l2[i], sep=' ')


import math
t = int(input())
while t > 0:
	n = int(input())
	print(2)
	l = [int(x) for x in range(1, n + 1)]
	k = n
	while k > 1:
		a = l[len(l) - 1]
		b = l[len(l) - 2]
		l.pop(len(l) - 1)
		l.pop(len(l) - 1)
		c = (a + b) / 2
		d = math.ceil(c)
		print(min(a, b), max(a, b))
		l.append(d)
		k -= 1
	t -= 1


from math import ceil

def board(n):
	arr = [i for i in range(1, n + 1)]
	ans = []
	const = 0
	while len(arr) > 1:
		const = ceil((arr[-1] + arr[-2]) / 2)
		ans.append([arr[-1], arr[-2]])
		arr.pop(-1)
		arr.pop(-1)
		arr.append(const)
	print(arr[0])
	for i in range(len(ans)):
		print(str(ans[i][0]) + ' ' + str(ans[i][1]))
t = int(input())
for i in range(t):
	board(int(input()))


from math import ceil
T = int(input())
for t in range(T):
	N = int(input())
	print(2)
	if N == 2:
		print(2, 1)
		continue
	removed = set()
	print(N, N - 2)
	print(N - 1, N - 1)
	i = 2
	val = N - 1
	while i < N - 1:
		print(val, val - 2)
		val -= 1
		i += 1


for testis in range(int(input())):
	n = int(input())
	print(2)
	k = n
	for i in range(n, 1, -1):
		print(str(i - 1) + ' ' + str(k))
		k = (k + i) // 2


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

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

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

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

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def NLI(n):
	return [[int(i) for i in input().split()] for i in range(n)]

def NLI_(n):
	return [[int(i) - 1 for i in input().split()] for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def RLI(n=8, a=1, b=10):
	return [random.randint(a, b) for i in range(n)]

def RI(a=1, b=10):
	return random.randint(a, b)

def INP():
	N = 10
	A = 10
	n = random.randint(1, N)
	a = [random.randint(1, A) for i in range(n)]
	return (n, a)

def Rtest(T):
	(case, err) = (0, 0)
	for i in range(T):
		inp = INP()
		a1 = naive(*inp)
		a2 = solve(*inp)
		if a1 != a2:
			print((a1, a2), inp)
			err += 1
		case += 1
	print('Tested', case, 'case with', err, 'errors')

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in R(base ** n):
		s = [tb // base ** bt % base for bt in R(n)]
		rt += [s]
	return rt

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

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()

class UnionFind:

	def __init__(self, n):
		self.table = [-1] * n

	def _root(self, x):
		if self.table[x] < 0:
			return x
		else:
			self.table[x] = self._root(self.table[x])
			return self.table[x]

	def find(self, x, y):
		return self._root(x) == self._root(y)

	def union(self, x, y):
		r1 = self._root(x)
		r2 = self._root(y)
		if r1 == r2:
			return
		d1 = self.table[r1]
		d2 = self.table[r2]
		if d1 <= d2:
			self.table[r2] = r1
			if d1 == d2:
				self.table[r1] -= 1
		else:
			self.table[r1] = r2

	def __str__(self):
		rt = [i if j < 0 else j for (i, j) in enumerate(self.table)]
		return str(rt)
show_flg = False
show_flg = True
ans = 0
for _ in range(I()):
	n = I()
	a = list(range(-n, 0))
	heapify(a)
	print(2)
	print(n, n - 1)
	for i in range(n, 2, -1):
		print(i, i - 2)


for _ in range(int(input())):
	a = int(input())
	print(2)
	print(a, a - 1)
	while a >= 3:
		print(a, a - 2)
		a -= 1


import sys, math, cmath, time, collections
start_time = time.time()

def solve():
	n = inp()
	a = [i + 1 for i in range(n)]
	print(2 if n >= 2 else 1)
	while len(a) >= 2:
		q = a.pop()
		w = a.pop()
		a.append(ceil(q + w, 2))
		print(q, w)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

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

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

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

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

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

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

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def power_two(x):
	return x and (not x & x - 1)

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

def seive(n):
	a = [1]
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return a
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


from math import ceil
for i in range(int(input())):
	n = int(input())
	print(2)
	a = n
	b = n - 1
	for j in range(1, n):
		print(a, b)
		a = (a + b + 1) // 2
		b = b - 1


for i in range(int(input())):
	n = int(input())
	l = [int(num) for num in range(n)]
	if n == 2:
		print(2)
		print(1, 2)
	else:
		print(2)
		print(n - 2, n)
		print(n - 1, n - 1)
		a = n - 1
		(e, o) = ([], [])
		for i in range(1, n - 2):
			if i % 2 == 0:
				e.append(i)
			else:
				o.append(i)
		while e != [] or o != []:
			if a % 2 == 0:
				print(e[len(e) - 1], a)
				a = (a + e[len(e) - 1]) // 2
				e.pop()
			else:
				print(o[len(o) - 1], a)
				a = (a + o[len(o) - 1]) // 2
				o.pop()


def whiteb(n):
	a = [i for i in range(1, n + 1)]
	b = [0] * (n - 1)
	for i in range(n - 1):
		tmp = a.pop()
		tmp2 = a[-1]
		a[-1] = (a[-1] + tmp) // 2 + (a[-1] + tmp) % 2
		b[i] = [tmp2, tmp]
	return [a[0], b]
n = int(input())
res = []
for i in range(n):
	p = int(input())
	res.append(whiteb(p))
for j in res:
	print(j[0])
	for k in j[1]:
		print(*k)


import time, math as mt, bisect, sys
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 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 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return

def readTree(v):
	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

def solve():
	n = II()
	a = [i for i in range(1, n + 1)]
	ln = n
	(i, j) = (n - 1, n - 2)
	print(2)
	while ln > 1:
		print(a[j], a[i])
		if (a[i] + a[j]) % 2:
			a[j] = (a[i] + a[j] + 1) // 2
		else:
			a[j] = (a[i] + a[j]) // 2
		i -= 1
		j -= 1
		ln -= 1
	return
t = II()
for i in range(t):
	solve()


import bisect
for _ in range(int(input())):
	n = int(input())
	l = []
	if n == 2:
		print(2)
		print(1, 2)
		continue
	l.append([n, n - 2])
	c = ((n + (n - 2)) // 2 + (n - 1)) // 2
	l.append([(n + n - 2) // 2, n - 1])
	for i in range(n - 3, 0, -1):
		d = c
		c = (c + i) // 2
		l.append([d, i])
	print(c)
	for i in l:
		print(i[0], i[1])


for _ in range(int(input())):
	n = int(input())
	x = n
	arr = []
	t = 0
	if n == 2:
		print(2)
		print(1, 2)
	else:
		arr.append([n, n - 2])
		x = int(round((n + n - 2) / 2, 0))
		arr.append([x, n - 1])
		x = int(round((x + n - 1) / 2, 0))
		for i in range(n - 3, 0, -1):
			arr.append([i, x])
			x = int(round((i + x) / 2, 0))
		print(x)
		for i in arr:
			print(*i)


from math import ceil
t = int(input())
for _ in range(t):
	n = int(input())
	print(2)
	a = list(range(1, n + 1))
	for i in range(n - 1):
		s1 = a.pop()
		s2 = a.pop()
		a.append(int(ceil((s1 + s2) / 2)))
		print(s1, s2)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(range(1, n + 1))
	print(2)
	while len(a) > 1:
		x = a.pop()
		y = a.pop()
		print('{} {}'.format(x, y))
		a.append((x + y + 1) // 2)


from math import ceil
for t in range(int(input())):
	n = int(input())
	print(2)
	a = [i for i in range(1, n + 1)]
	for i in range(n - 1):
		c = ceil((a[-1] + a[-2]) / 2)
		print(a[-1], a[-2])
		a.pop()
		a.pop()
		a.append(c)


from math import ceil
cases = int(input())
for _ in range(cases):
	n = int(input())
	nums = list([i for i in range(1, n + 1)])
	output = []
	while len(nums) > 1:
		l = nums.pop()
		i = -1
		if len(nums) >= 2 and (nums[-2] + l) % 2 == 0:
			i = -2
		if (nums[-1] + l) % 2 == 0:
			i = -1
		output.append(f'{nums[i]} {l}')
		nums[i] = ceil((l + nums[i]) / 2)
	print(nums[0])
	for line in output:
		print(line)


f = int(input())
for i in range(f):
	n = int(input())
	print(2)
	print(n, n - 1)
	for i in range(n - 2):
		print(n - i, n - 2 - i)


import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq

def input():
	return sys.stdin.readline()[:-1]

def solve(N):
	if N == 2:
		print(2)
		print(1, 2)
	elif N == 3:
		print(2)
		print(1, 3)
		print(2, 2)
	else:
		print(2)
		print(N - 2, N)
		print(N - 1, N - 1)
		k = N - 3
		while k >= 1:
			print(k, k + 2)
			k -= 1
T0 = int(input())
for _ in range(T0):
	N = int(input())
	solve(N)


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict, Counter
from os import path
import bisect as bi
import heapq
mod = 10 ** 9 + 7

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

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

	def minp():
		return map(int, input().split())
else:

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

	def minp():
		return map(int, stdin.readline().split())
for _ in range(inp()):
	n = inp()
	print(2)
	if n == 2:
		print(1, 2)
		continue
	a = [x for x in range(1, n + 1)]
	if n & 1:
		for i in range(n - 1, 0, -1):
			print(a[i], a[i - 1])
			a[i - 1] = math.ceil((a[i] + a[i - 1]) / 2)
	else:
		print(a[n - 1], a[n - 3])
		a[n - 3] = math.ceil((a[n - 3] + a[n - 1]) / 2)
		for i in range(n - 2, 0, -1):
			print(a[i], a[i - 1])
			a[i - 1] = math.ceil((a[i] + a[i - 1]) / 2)


for u in range(int(input())):
	n = int(input())
	a = n
	print(2)
	while n > 1:
		a = (a + n + 1) // 2
		print(a, n - 1)
		n -= 1


from functools import reduce
import os
import sys
from collections import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

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

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

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
inf = 1e+18
div = 998244353
for _ in range(inn()):
	n = inn()
	if n == 2:
		print(2)
		print(1, 2)
	else:
		print(2)
		print(n, n - 2)
		print(n - 1, n - 1)
		a = [i for i in range(1, n - 2)]
		a += [n - 1]
		ln = len(a)
		for i in range(ln - 1, 0, -1):
			print(a[i], a[i - 1])
			a[i - 1] = ceil((a[i] + a[i - 1]) / 2)


def main():
	t = int(input())
	for __ in range(t):
		n = int(input())
		if n == 2:
			print(2)
			print(1, 2)
		else:
			print(2)
			s = set()
			a = n
			b = n - 2
			for i in range(n - 1):
				print(a, b)
				if a == n:
					a = n - 1
					b = n - 1
				elif a == b:
					b = a - 2
				else:
					a = a - 1
					b = a - 2
main()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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))
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
mod = 10 ** 9 + 7

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 zerolist(n):
	return [0] * n

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

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

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

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

def power(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

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	n = int(inp())
	ans = []
	print(2)
	if n == 2:
		print(1, 2)
		return
	print(n, n - 2)
	print(n - 1, n - 1)
	for i in range(n - 3):
		print(n - 1, n - 3)
		n -= 1
testcase(int(inp()))


from collections import Counter
from sys import stdin, stdout
from math import ceil

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

def solve():
	n = II()
	ans = n
	erased = []
	for i in range(n - 1, 0, -1):
		erased.append((i, ans))
		ans = ceil((ans + i) / 2)
	stdout.write(str(ans) + '\n')
	for (x, y) in erased:
		stdout.write('{} {}\n'.format(x, y))
t = II()
for _ in range(t):
	solve()


t = int(input())
for case in range(t):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
		continue
	print(n - 2, n)
	print(n - 1, n - 1)
	k = n - 1 - 2
	w = n - 1
	for _ in range(k):
		print(w - 2, w)
		w -= 1


t = int(input())
for i in range(t):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	else:
		print(2)
		print(n - 1, n)
		(x, y) = (n - 2, n)
		for i in range(n - 2):
			print(x, y)
			x = x - 1
			y = y - 1


t = int(input())
import math

def ceil(p, q):
	s = p + q
	if s & 1:
		return (s + 1) // 2
	return s // 2

def compute(n):
	nums = list(range(1, n + 1))
	count = 0
	num = nums[-1]
	result = []
	for j in range(len(nums) - 2, -1, -1):
		p = nums[j]
		q = num
		result.append([p, q])
		nxt = ceil(p, q)
		num = nxt
	print(num)
	for (x, y) in result:
		print('%s %s' % (x, y))
for _ in range(t):
	n = int(input())
	compute(n)


from math import ceil
for _ in range(int(input())):
	n = int(input())
	print(2)
	x = n - 1
	y = n
	while x > 0:
		print(x, y)
		y = ceil((x + y) / 2)
		x -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	else:
		lis = [(n - 2, n)]
		num = (n + n - 2) // 2
		lis.append((num, n - 1))
		num = (num + n - 1) // 2
		i = n - 3
		while i > 0:
			lis.append((num, i))
			num = (num + i) // 2
			i -= 1
		print(num)
		for item in lis:
			print(item[0], item[1])


def solve(n):
	if n == 2:
		print(2)
		print(2, 1)
		return
	print(2)
	print(n, n - 2)
	print(n - 1, n - 1)
	m = n - 1
	i = 3
	while n - i >= 1:
		print(m, n - i)
		m = (m + n - i) // 2
		i += 1
for _ in range(int(input())):
	solve(int(input()))


t = int(input())
for j in range(t):
	n = int(input())
	a = True
	if n == 2:
		print(2)
		print(1, 2)
	else:
		print(2)
		cnt = 0
		print(n, n - 2)
		print(n - 1, n - 1)
		for j in range(n - 1, 0, -1):
			if cnt == n - 3:
				break
			print(j, j - 2)
			cnt += 1


t = int(input())
for _ in range(t):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	else:
		a = list(range(n + 1))[1:]
		print(2)
		print(n, n - 2)
		a[n - 3] = (a[n - 1] + a[n - 3]) // 2
		n -= 1
		while n > 1:
			print(a[n - 1], a[n - 2])
			a[n - 2] = (a[n - 1] + a[n - 2]) // 2
			n -= 1


import io, os
R = lambda : map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
		continue
	print(n, n - 2)
	print(n - 1, n - 1)
	for i in range(n - 3):
		print(n - i - 1, n - i - 3)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	print(2)
	x = math.ceil((n + n - 1) / 2)
	for i in range(n, 1, -1):
		x = math.ceil((i + x) / 2)
		print(i - 1, x)


import sys
import math
from collections import Counter, defaultdict
LI = lambda : list(map(int, input().split()))
MAP = lambda : map(int, input().split())
IN = lambda : int(input())
S = lambda : input()

def case():
	n = IN()
	if n == 2:
		print(2)
		print(1, 2)
	else:
		print(2)
		print(n, n - 1)
		x = n
		for i in range(n - 2):
			print(x, x - 2)
			x -= 1
for _ in range(IN()):
	case()


t = int(input())
for i in range(t):
	n = int(input())
	if n == 1:
		print('1')
		print('1')
	elif n == 2:
		print('2')
		print('1 2')
	else:
		print('2')
		print(str(n - 2) + ' ' + str(n))
		print(str(n - 1) + ' ' + str(n - 1))
		i = 3
		while n - i > 0:
			print(str(n - i) + ' ' + str(n - i + 2))
			i += 1


from math import ceil
for _ in range(int(input())):
	n = int(input())
	l = []
	print(2)
	x = n
	y = n - 1
	for i in range(n - 1):
		print(x, y)
		z = y
		x = ceil((x + y) / 2)
		y = y - 1


t = int(input())
for f in range(t):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
	elif n == 3:
		print(1, 3)
		print(2, 2)
	else:
		print(n - 2, n)
		print(n - 1, n - 1)
		for i in range(1, n - 2):
			print(n - i, n - i - 2)


import math

def main():
	test = int(input())
	for x in range(test):
		n = int(input())
		print(2)
		current = n
		for i in range(n - 1, 0, -1):
			print(str(i) + ' ' + str(current))
			current = math.ceil((i + current) / 2)
main()


for _ in range(int(input())):
	x = int(input())
	print(2)
	print(x - 1, x)
	q = x - 2
	t = x
	for c in range(x - 2):
		print(q, t)
		q -= 1
		t -= 1


from math import ceil
t = int(input())
for _ in range(t):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
	else:
		fir = n - 2
		sec = n
		times = n - 3
		print(fir, sec)
		avg = (fir + sec) // 2
		print(avg, avg)
		for _ in range(n - 3):
			print(avg, avg - 2)
			avg -= 1


t = int(input())
for i in range(t):
	n = int(input())
	print(2)
	if n == 2:
		a = n
		b = 1
	else:
		a = n
		b = (n - 1) * 2 - a
	c = n - 1
	for i in range(n - 1):
		print(a, b)
		a = (a + b) // 2
		b = c * 2 - a
		c = c - 1


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(range(1, n + 1))
	ans = []
	t = -1
	for i in range(n - 1):
		ans.append((A[-2], A[-1]))
		x = A.pop()
		if (x + A[-1]) % 2 == 0:
			A[-1] = (x + A[-1]) // 2
		else:
			A[-1] = (x + A[-1] + 1) // 2
	print(A[0])
	for i in range(len(ans)):
		print(*ans[i])


class Solution:

	def __init__(self):
		self.found = -1
		self.pattern = []
		self.three = 0
		self.five = 0
		self.seven = 0

	@staticmethod
	def whiteboard(number):
		num1 = number
		num2 = number - 1
		iters = number - 1
		print(2)
		while iters:
			print(num1, num2)
			sum1 = num1 + num2
			if sum1 % 2 == 0:
				avg = sum1 // 2
			else:
				avg = (sum1 + 1) // 2
			num1 = avg
			num2 = num2 - 1
			iters -= 1
num = int(input())
while num:
	number = int(input())
	Solution.whiteboard(number)
	num -= 1


import sys
import math
from functools import reduce
import bisect

def getN():
	return int(input())

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

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

def input():
	return sys.stdin.readline().rstrip()

def index(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	return False
for _ in range(getN()):
	n = int(input())
	print(2)
	print(n - 1, n)
	for i in range(n - 2):
		print(n - 2 - i, n - i)


test = int(input())
for _ in range(test):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	elif n == 3:
		print(2)
		print(2, 3)
		print(1, 3)
	else:
		print(2)
		print(n - 1, n)
		print(n - 2, n)
		j = 1
		for i in range(n - 3, 0, -1):
			print(i, n - j)
			j += 1


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


import sys, math
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	chet = []
	nechet = []
	(l1, l2) = (n // 2, n // 2 + n % 2)
	for i in range(1, n + 1):
		if i % 2 == 0:
			chet.append(i)
		else:
			nechet.append(i)
	ans = []
	while True:
		if l1 > 1 and l2 > 1:
			if chet[l1 - 2] + chet[l1 - 1] > nechet[l2 - 1] + nechet[l2 - 2]:
				a = chet[l1 - 2]
				b = chet[l1 - 1]
				del chet[l1 - 1]
				del chet[l1 - 2]
				l1 -= 2
				if (a + b + 1) // 2 % 2 == 0:
					l1 += 1
					chet.append((a + b + 1) // 2)
				else:
					l2 += 1
					nechet.append((a + b + 1) // 2)
				ans.append(a)
				ans.append(b)
			else:
				a = nechet[l2 - 2]
				b = nechet[l2 - 1]
				del nechet[l2 - 1]
				del nechet[l2 - 2]
				l2 -= 2
				if (a + b + 1) // 2 % 2 == 0:
					l1 += 1
					chet.append((a + b + 1) // 2)
				else:
					l2 += 1
					nechet.append((a + b + 1) // 2)
				ans.append(a)
				ans.append(b)
		elif l2 > 1:
			a = nechet[l2 - 2]
			b = nechet[l2 - 1]
			del nechet[l2 - 1]
			del nechet[l2 - 2]
			l2 -= 2
			if (a + b + 1) // 2 % 2 == 0:
				l1 += 1
				chet.append((a + b + 1) // 2)
			else:
				l2 += 1
				nechet.append((a + b + 1) // 2)
			ans.append(a)
			ans.append(b)
		elif l1 > 1:
			a = chet[l1 - 2]
			b = chet[l1 - 1]
			del chet[l1 - 1]
			del chet[l1 - 2]
			l1 -= 2
			if (a + b + 1) // 2 % 2 == 0:
				l1 += 1
				chet.append((a + b + 1) // 2)
			else:
				l2 += 1
				nechet.append((a + b + 1) // 2)
			ans.append(a)
			ans.append(b)
		elif l1 != 0 and l2 != 0:
			a = nechet[0]
			b = chet[0]
			print((a + b + 1) // 2)
			for i in range(len(ans)):
				print(ans[i], end=' ')
				if i % 2 == 1:
					print()
			print(a, b)
			break
		else:
			if l1 == 0:
				print(nechet[0])
				for i in range(len(ans)):
					print(ans[i], end=' ')
					if i % 2 == 1:
						print()
			else:
				print(chet[0])
				for i in range(len(ans)):
					print(ans[i], end=' ')
					if i % 2 == 1:
						print()
			break


t = int(input())
for ii in range(t):
	n = int(input())
	print(2)
	l = list(range(0, n + 1))
	fl = [False] * (n + 1)
	cur = n
	fl[-1] = True
	ptr = max(n - 2, 1)
	for i in range(n - 1):
		print(cur, l[ptr])
		cur = (cur + l[ptr]) // 2
		fl[ptr] = True
		if ptr + 1 < n and fl[ptr + 1] != True:
			ptr += 1
		else:
			while ptr > 1 and (fl[ptr] or (l[ptr] + cur) % 2 != 0):
				ptr -= 1


for _ in range(int(input())):
	n = int(input())
	if n <= 2:
		print(2)
		print(1, 2)
	else:
		print(2)
		lis = []
		for i in range(1, n + 1, 1):
			lis.append(i)
		print(lis[-1], lis[-3])
		lis.pop()
		va = lis.pop()
		lis.pop()
		lis.append(va)
		lis.append(va)
		while len(lis) >= 2:
			print(lis[-1], lis[-2])
			v1 = lis.pop()
			v2 = lis.pop()
			lis.append((v1 + v2) // 2)


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

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
from math import ceil, floor, sqrt, pow
for _ in range(N()):
	n = N()
	res = []
	now = list(range(1, n + 1))
	for _ in range(n - 1):
		(a, b) = (now.pop(), now.pop())
		res.append([a, b])
		now.append(ceil((a + b) / 2))
	print(now[-1])
	for i in res:
		print_list(i)


for _ in range(int(input())):
	n = int(input())
	l = []
	ans = []
	for i in range(1, n + 1):
		l.append(i)
	while len(l) > 1:
		x = l[-1]
		l.pop()
		y = l[-1]
		l.pop()
		ans.append([x, y])
		l.append((x + y + 1) // 2)
	print(l[0])
	for i in range(len(ans)):
		print(ans[i][0], ans[i][1])


from sys import stdin
from math import ceil

def whiteboard(n):
	compute = lambda a, b: ceil((a + b) / 2)
	values = list(range(1, n + 1))
	operations = []
	while len(operations) < n - 1:
		maxval = values.pop()
		i = len(values) - 1
		while i > 0 and (values[i] + maxval) % 2 != 0:
			i -= 1
		minval = values.pop(i)
		values.append(compute(minval, maxval))
		operations.append((minval, maxval))
	print(values[0])
	for (a, b) in operations:
		print(f'{a} {b}')
readint = lambda : int(stdin.readline())
t = readint()
cases = [readint() for _ in range(t)]
for n in cases:
	whiteboard(n)


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

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

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write('\n'.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = float('inf')
mod = 10 ** 9 + 7
for t in range(int(data())):
	n = int(data())
	out(2)
	ans = []
	k = n
	for i in range(n - 1, 0, -1):
		ans.append(str(k) + ' ' + str(i))
		k = (k + i + 1) // 2
	outl(ans)


o = []
for _ in [0] * int(input()):
	n = int(input()) - 1
	o += [['2\n1 2'], [f'2\n{n - 1} {n + 1}\n{n} {n}'] + [f'{n - 2 - i} {n - i}' for i in range(n - 2)]][n > 1]
print('\n'.join(o))


import sys
input = sys.stdin.buffer.readline
T = int(input())
for testcase in range(T):
	n = int(input())
	print(2)
	print(n, n - 1)
	for i in range(n, 2, -1):
		print(i, i - 2)


t = int(input())
for m in range(t):
	n = int(input())
	if n == 2:
		print(2)
		print(2, 1)
	else:
		(p, q) = (n, n - 2)
		print(2)
		print(p, q)
		print(n - 1, n - 1)
		i = 1
		while p != 3 and q != 1:
			p = n - i
			q = n - i - 2
			print(p, q)
			i += 1


t = int(input())
ns = []
for _ in range(t):
	n = int(input())
	ns.append(n)
for n in ns:
	print(2)
	print(n - 1, n)
	if n > 2:
		for x in range(n, 2, -1):
			print(x - 2, x)


import heapq
from math import ceil
for _ in range(int(input())):
	n = int(input())
	x = []
	for i in range(1, n + 1):
		heapq.heappush(x, -i)
	s = []
	while len(x) != 1:
		h = heapq.heappop(x)
		l = heapq.heappop(x)
		s.append(str(f'{-l} {-h}'))
		if (h + l) % 2:
			h -= 1
		heapq.heappush(x, ceil((h + l) / 2))
	print(-x[0])
	print('\n'.join(s))


test_cases = int(input())
for t in range(test_cases):
	n = int(input())
	nums = [int(i > 0) for i in range(n + 1)]
	p = n
	print(2)
	while p > 2:
		if nums[p] == 2:
			print(p, p)
			nums[p] = 1
			continue
		if nums[p] == 0:
			p -= 1
			continue
		if nums[p] == 1 and nums[p - 2] == 1:
			print(p, p - 2)
			(nums[p], nums[p - 2]) = (0, 0)
			nums[p - 1] += 1
			p -= 1
	if p == 2:
		if nums[p] == 2:
			print(2, 2)
			nums[p] = 1
		if nums[1] == 1 and nums[2] == 1:
			print(2, 1)


for _ in range(int(input())):
	n = int(input())
	print(2, flush=False)
	print(f'{n} {n - 1}', flush=False)
	if n > 2:
		print('\n'.join((f'{x} {x - 2}' for x in range(n, 2, -1))))


from functools import cmp_to_key
from collections import deque, Counter
from heapq import heappush, heappop
from math import log, ceil
import sys
import os
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')
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))

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

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

def ii():
	return int(inp())

def si():
	return str(inp())

def li(lag=0):
	l = list(map(int, inp().split()))
	if lag != 0:
		for i in range(len(l)):
			l[i] += lag
	return l

def mi(lag=0):
	matrix = list()
	for i in range(n):
		matrix.append(li(lag))
	return matrix

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

def print_list(lista, space=' '):
	print(space.join(map(str, lista)))

def bisect_left(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] < x:
			left = mid + 1
		else:
			right = mid
	return left

def bisect_right(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] > x:
			right = mid
		else:
			left = mid + 1
	return left

def bisect_elements(a, x):
	return bisect_right(a, x) - bisect_left(a, x)
MOD = 10 ** 9 + 7
maxN = 5
FACT = [0] * maxN
INV_FACT = [0] * maxN

def add(x, y):
	return (x + y) % MOD

def multiply(x, y):
	return x * y % MOD

def power(x, y):
	if y == 0:
		return 1
	elif y % 2:
		return multiply(x, power(x, y - 1))
	else:
		a = power(x, y // 2)
		return multiply(a, a)

def inverse(x):
	return power(x, MOD - 2)

def divide(x, y):
	return multiply(x, inverse(y))

def allFactorials():
	FACT[0] = 1
	for i in range(1, maxN):
		FACT[i] = multiply(i, FACT[i - 1])

def inverseFactorials():
	n = len(INV_FACT)
	INV_FACT[n - 1] = inverse(FACT[n - 1])
	for i in range(n - 2, -1, -1):
		INV_FACT[i] = multiply(INV_FACT[i + 1], i + 1)

def coeffBinom(n, k):
	if n < k:
		return 0
	return multiply(FACT[n], multiply(INV_FACT[k], INV_FACT[n - k]))

def create_graph(n, m, undirected=1, unweighted=1):
	graph = [[] for i in range(n)]
	if unweighted:
		for i in range(m):
			[x, y] = li(lag=-1)
			graph[x].append(y)
			if undirected:
				graph[y].append(x)
	else:
		for i in range(m):
			[x, y, w] = li(lag=-1)
			w += 1
			graph[x].append([y, w])
			if undirected:
				graph[y].append([x, w])
	return graph

def create_tree(n, unweighted=1):
	children = [[] for i in range(n)]
	if unweighted:
		for i in range(n - 1):
			[x, y] = li(lag=-1)
			children[x].append(y)
			children[y].append(x)
	else:
		for i in range(n - 1):
			[x, y, w] = li(lag=-1)
			w += 1
			children[x].append([y, w])
			children[y].append([x, w])
	return children

def dist(tree, n, A, B=-1):
	s = [[A, 0]]
	(massimo, massimo_nodo) = (0, 0)
	distanza = -1
	v = [-1] * n
	while s:
		(el, dis) = s.pop()
		if dis > massimo:
			massimo = dis
			massimo_nodo = el
		if el == B:
			distanza = dis
		for child in tree[el]:
			if v[child] == -1:
				v[child] = 1
				s.append([child, dis + 1])
	return (massimo, massimo_nodo, distanza)

def diameter(tree):
	(_, foglia, _) = dist(tree, n, 0)
	(diam, _, _) = dist(tree, n, foglia)
	return diam

def dfs(graph, n, A):
	v = [-1] * n
	s = [[A, 0]]
	v[A] = 0
	while s:
		(el, dis) = s.pop()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def bfs(graph, n, A):
	v = [-1] * n
	s = deque()
	s.append([A, 0])
	v[A] = 0
	while s:
		(el, dis) = s.popleft()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def parents_children_root_unrooted_tree(tree, n, root=0):
	q = deque()
	visited = [0] * n
	parent = [-1] * n
	children = [[] for i in range(n)]
	q.append(root)
	while q:
		all_done = 1
		visited[q[0]] = 1
		for child in tree[q[0]]:
			if not visited[child]:
				all_done = 0
				q.appendleft(child)
		if all_done:
			for child in tree[q[0]]:
				if parent[child] == -1:
					parent[q[0]] = child
					children[child].append(q[0])
			q.popleft()
	return (parent, children)

def all_longest_path_passing_from_node(parent, children, n):
	q = deque()
	visited = [len(children[i]) for i in range(n)]
	downwards = [[0, 0] for i in range(n)]
	upward = [1] * n
	longest_path = [1] * n
	for i in range(n):
		if not visited[i]:
			q.append(i)
			downwards[i] = [1, 0]
	while q:
		node = q.popleft()
		if parent[node] != -1:
			visited[parent[node]] -= 1
			if not visited[parent[node]]:
				q.append(parent[node])
		else:
			root = node
		for child in children[node]:
			downwards[node] = sorted([downwards[node][0], downwards[node][1], downwards[child][0] + 1], reverse=True)[0:2]
	s = [node]
	while s:
		node = s.pop()
		if parent[node] != -1:
			if downwards[parent[node]][0] == downwards[node][0] + 1:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][1])
			else:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][0])
		longest_path[node] = downwards[node][0] + downwards[node][1] + upward[node] - min([downwards[node][0], downwards[node][1], upward[node]]) - 1
		for child in children[node]:
			s.append(child)
	return longest_path

def f(a, b):
	return (a + b + 1) // 2
for test in range(ii()):
	n = ii()
	print(2)
	residuo = n
	for i in range(n - 1, 0, -1):
		print_list([i, residuo])
		residuo = f(residuo, i)


import sys
import math

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()
for _ in range(int(input())):
	n = int(input())
	print(2)
	print(n - 1, n)
	for i in range(n - 2):
		print(n - i - 2, n - i)


import math
for _ in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	else:
		print(2)
		a = [x for x in range(1, n + 1)]
		for i in range(1, n):
			if i == 1:
				print(a[-1], a[-3])
				a[-3] = a[-2]
			else:
				print(a[-i], a[-i - 1])
				a[-i - 1] = math.ceil((a[-i] + a[-i - 1]) / 2)


import sys, math
input = sys.stdin.readline
t = int(input())
for r in range(t):
	n = int(input())
	l = []
	for i in range(1, n + 1):
		l.append(i)
	l = l[::-1]
	print(2)
	current = math.ceil((l[0] + l[1]) / 2)
	print(l[0], l[1])
	for i in range(2, n):
		print(current, l[i])
		current = math.ceil((current + l[i]) / 2)


for n in [*open(0)][1:]:
	print(2)
	n = int(n)
	for i in range(n, 1, -1):
		print(i - 1, n)
		n = n + i >> 1


for _ in range(int(input())):
	n = int(input())
	if n == 1:
		print(1)
		continue
	print(2)
	if n == 2:
		print('1 2')
	elif n == 3:
		print('1 3')
		print('2 2')
	else:
		print('{} {}'.format(n, n - 2))
		print('{} {}'.format(n - 1, n - 1))
		for i in range(n - 1, 2, -1):
			print('{} {}'.format(i, i - 2))


import math
for _ in ' ' * int(input()):
	n = int(input())
	a = [i for i in range(1, n + 1)]
	f = 0
	if n == 2:
		print(2)
		print(1, 2)
	else:
		lst = []
		while len(a) > 1:
			lst.append([a[-1], a[-2]])
			x = math.ceil((a[-1] + a[-2]) / 2)
			a.pop()
			a.pop()
			a.append(x)
		print(math.ceil((lst[-1][0] + lst[-1][1]) / 2))
		for i in range(len(lst)):
			print(*lst[i])


def solve(r):
	print(2)
	print(r - 1, r)
	for i in range(r - 2):
		print(r - i - 2, r - i)
t = int(input())
for i in range(t):
	r = int(input())
	solve(r)


from sys import stdin, stdout
from math import ceil
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	n = inp()
	now = n
	nex = n - 1
	ans = []
	for i in range(n - 1):
		ans.append((now, nex))
		now = ceil((nex + now) / 2)
		nex -= 1
	val = ceil(sum(ans[-1]) / 2)
	print(val)
	for i in ans:
		print(*i)
for _ in range(inp()):
	solve()


t = int(input())
for _ in range(t):
	arr = []
	n = int(input())
	cur = n
	for i in range(n - 1, 0, -1):
		arr.append([cur, i])
		if (i + cur) % 2 == 0:
			cur = (i + cur) // 2
		else:
			cur = (i + cur + 1) // 2
	print(cur)
	for i in range(len(arr)):
		print(*arr[i], sep=' ')


import math
t = int(input())
for z in range(t):
	n = int(input())
	operations = []
	if n == 1:
		print(1)
	arr = sorted([i for i in range(1, n + 1)], reverse=True)
	for i in range(n - 1):
		operations.append((arr[i], arr[i + 1]))
		arr[i + 1] = math.ceil((arr[i] + arr[i + 1]) / 2)
	print(arr[n - 1])
	for oper in operations:
		print(oper[0], oper[1])


from math import ceil
t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	print(2)
	a = list(reversed(range(1, n + 1)))
	p = ceil((a[0] + a[1]) / 2)
	print(a[0], a[1])
	i = 2
	while i < len(a):
		print(p, a[i])
		p = ceil((p + a[i]) / 2)
		i += 1


for _ in range(int(input())):
	n = int(input())
	arr = [i for i in range(1, n + 1)]
	print(2)
	while len(arr) > 1:
		first = arr.pop()
		sec = arr.pop()
		avg = (first + sec) / 2
		if avg > int(avg):
			avg = int(avg) + 1
		else:
			avg = int(avg)
		arr.append(avg)
		print(sec, first)


t = int(input())
for i in range(t):
	n = int(input())
	print(2)
	print(str(n) + ' ' + str(n - 1))
	for i in range(n - 2):
		print(str(n - i) + ' ' + str(n - 2 - i))


t = int(input())
for p in range(t):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	else:
		res = []
		res.append([n, n - 2])
		res.append([n - 1, n - 1])
		l = 2
		curr = n - 1
		while l < n - 1:
			res.append([curr - 2, curr])
			curr -= 1
			l += 1
		l += 1
		print(2)
		for j in res:
			print(*j)


from collections import deque as dq
for _ in range(int(input())):
	n = int(input())
	p = n
	if n == 2:
		print(2)
		print(1, 2)
		continue
	elif n == 3:
		print(2)
		print(1, 3)
		print(2, 2)
	else:
		st = dq([i for i in range(1, n + 1)])
		print(2)
		(a, b, c) = (st.pop(), st.pop(), st.pop())
		st.append(b)
		st.append((a + c) // 2)
		print(a, c)
		while len(st) > 1:
			x = st.pop()
			y = st.pop()
			print(x, y)
			st.append((x + y) // 2)


import math
T = int(input())
for t in range(T):
	n = int(input())
	A = []
	res = []
	for i in range(1, n + 1):
		A.append(i)
	for i in range(n - 1):
		a = A.pop()
		mc = math.ceil((a + A[len(A) - 1]) / 2)
		res.append([a, A[len(A) - 1]])
		A[len(A) - 1] = mc
	print(A[0])
	for i in range(len(res)):
		print(res[i][0], res[i][1])


from heapq import heapify, heappop, heappush
for _ in range(int(input())):
	n = int(input())
	A = [-1 * int(_) for _ in range(1, n + 1)]
	heapify(A)
	X = []
	for _ in range(n - 1):
		x = heappop(A) * -1
		y = heappop(A) * -1
		X.append([x, y])
		heappush(A, -1 * ((x + y + 1) // 2))
	print(heappop(A) * -1)
	for _ in X:
		print(*_)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
getcontext().prec = 25
from itertools import permutations
MOD = pow(10, 9) + 7
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')
for _ in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	else:
		print(2)
		val = n - 2
		cond = False
		used = []
		print(n, val)
		n = n - 1
		print(n, n)
		for i in range(n - 2):
			print(n, n - 2)
			n = n - 1


import math
t = int(input())
for q in range(t):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
		continue
	print(n, n - 2)
	print(n - 1, n - 1)
	for i in range(n - 3):
		print(n - i - 1, n - i - 3)


def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(range(1, n + 1))
		l = []
		if n == 2:
			l.append((n, n - 1))
		if n >= 3:
			l.append((n, n - 2))
			l.append((n - 1, n - 1))
		k = 1
		for i in range(n - 3):
			l.append((n - k, n - 2 - k))
			k += 1
		print((l[-1][0] + l[-1][1]) // 2 + (l[-1][0] + l[-1][1]) % 2)
		for i in l:
			print(*i)
main()


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

def inar():
	return [int(el) for el in input().split()]

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		print(2)
		arr = [i for i in range(1, n + 1)]
		while True:
			el1 = arr.pop()
			el2 = arr.pop()
			arr.append(math.ceil((el1 + el2) / 2))
			print(el2, el1)
			if len(arr) == 1:
				break
main()


t = int(input())
for _ in range(t):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
	else:
		print(n, n - 2)
		print(n - 1, n - 1)
		n -= 1
		while n > 2:
			print(n, n - 2)
			n -= 1


numCases = int(input())
while numCases > 0:
	qtdNum = int(input())
	x = qtdNum - 1
	print('2')
	maior = qtdNum
	numCases -= 1
	while x > 0:
		str = '{0} {1}'
		print(str.format(x, maior))
		maior = int((maior + x + 1) / 2)
		x -= 1


for u in range(int(input())):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
	else:
		print(n - 2, n)
		r = (n + (n - 2)) // 2
		for i in range(n - 1, 0, -1):
			if i == n - 2:
				continue
			else:
				print(i, r)
				r = (i + r) // 2


import os
import sys
import math
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')
readint = lambda : int(sys.stdin.readline().rstrip('\r\n'))
readints = lambda : map(int, sys.stdin.readline().rstrip('\r\n').split())
readstr = lambda : sys.stdin.readline().rstrip('\r\n')
readstrs = lambda : map(str, sys.stdin.readline().rstrip('\r\n').split())
readarri = lambda : [int(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]
readarrs = lambda : [str(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]

def main():
	for _ in range(readint()):
		n = readint()
		arr = [i for i in range(1, n + 1)]
		a = arr[-1]
		b = arr[-2]
		ans = []
		for i in range(n - 1):
			temp = math.ceil((a + b) / 2)
			ans.append([a, b])
			del arr[-1]
			del arr[-1]
			arr.append(temp)
			if i != n - 2:
				a = arr[-1]
				b = arr[-2]
		print(arr[0])
		for i in ans:
			print(*i)
main()


import sys
import random
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
input = sys.stdin.readline
getS = lambda : input().strip()
getN = lambda : int(input())
getList = lambda : list(map(int, input().split()))
getZList = lambda : [int(x) - 1 for x in input().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
divide = lambda x: pow(x, MOD - 2, MOD)

def judge(at, ax, ay, bt, bx, by):
	if abs(at - bt) >= abs(ax - bx) + abs(ay - by):
		return True
	else:
		return False

def solve():
	n = getN()
	if n == 2:
		print(2)
		print(1, 2)
		return
	print(2)
	print(n - 2, n)
	print(n - 1, n - 1)
	for i in range(n - 3):
		print(n - 1 - i, n - 3 - i)
	return

def main():
	n = getN()
	for _ in range(n):
		solve()
	return

def __starting_point():
	main()
__starting_point()


T = int(input())
while T > 0:
	n = int(input())
	print(2)
	(now, before) = (n, n - 1)
	for i in range(n - 1):
		print(str(now) + ' ' + str(before))
		now = (now + before + 1) // 2
		before -= 1
	T -= 1


t = int(input())
while t:
	t -= 1
	n = int(input())
	print(2)
	arr = [n - 1, n]
	print(*arr)
	for i in range(2, n):
		arr = [n - i, n - i + 2]
		print(*arr)


import sys
import math

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

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

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

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	n = II()
	if n == 2:
		print(2)
		print(1, 2)
		continue
	a = [i for i in range(1, n + 1)]
	ans = []
	for i in range(n - 1):
		if i == 0:
			ans.append([a[-1], a[-3]])
			x = a.pop()
			y = a.pop(-2)
			a.append((x + y) // 2)
		else:
			x = a.pop()
			y = a.pop()
			a.append((x + y) // 2)
			ans.append([x, y])
	print(a[0])
	for i in ans:
		print(*i)


n = int(input())
for i in range(0, n):
	x = int(input())
	if x == 2:
		print(2)
		print(2, 1)
	else:
		print(2)
		print(x, x - 1)
		for j in range(x - 2):
			print(x, x - 2)
			x = x - 1


import math
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list((i for i in range(1, n + 1)))
	print(2)
	while len(a) > 1:
		k1 = a.pop()
		k2 = a.pop()
		print(k1, k2)
		a.append(int(math.ceil((k1 + k2) / 2.0)))


t = int(input())
for i in range(t):
	n = int(input())
	print(2)
	print('{} {}'.format(n - 1, n))
	for i in range(n, 2, -1):
		print('{} {}'.format(i, i - 2))


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
mod = 1000000007

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

def N():
	return int(inp())

def solve():
	n = N()
	ar = [-i for i in range(1, n + 1)]
	heapify(ar)
	answer = []
	while len(ar) > 1:
		a = -heappop(ar)
		b = -heappop(ar)
		c = ceil((a + b) / 2)
		answer.append((a, b))
		heappush(ar, -c)
	print(abs(ar[0]))
	for i in answer:
		print(*i)
testcase(int(inp()))


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [x for x in range(1, n + 1)]
	print(2)
	while len(arr) > 1:
		b = arr.pop()
		a = arr.pop()
		print(a, b)
		arr.append((a + b + 1) // 2)


for i in range(int(input())):
	n = int(input())
	k = 0
	val = n
	if n == 2:
		print('2')
		print('1 2')
	else:
		ga = []
		gb = []
		ga.append(n - 2)
		gb.append(n)
		ga.append(n - 1)
		gb.append(n - 1)
		for j in range(n - 1, 2, -1):
			ga.append(j)
			gb.append(j - 2)
		print('2')
		for j in range(n - 1):
			print(ga[j], gb[j])


import math
cases = int(input())
for t in range(cases):
	n = int(input())
	print(2)
	print(n - 1, n)
	v = n
	for i in range(n - 2, 0, -1):
		print(i, v)
		v = math.ceil((i + v) / 2)


for test in range(int(input())):
	n = int(input())
	print(2)
	res = []
	if n == 2:
		res.append((2, 1))
	else:
		res.append((n, n - 2))
		res.append((n - 1, n - 1))
		n -= 1
	while n > 2:
		res.append((n, n - 2))
		n -= 1
	for r in res:
		print(*r)


t = int(input())
for i in range(t):
	n = int(input())
	li = [i for i in range(1, n + 1)]
	j = []
	while len(li) > 1:
		a = li.pop()
		if (a + li[-1]) / 2 == (a + li[-1]) // 2:
			b = li.pop()
		elif len(li) == 1:
			b = li.pop(0)
		else:
			b = li.pop(-2)
		k = round((a + b) / 2)
		li.append(k)
		j.append((a, b))
	print(*li)
	for i in j:
		print(*i)


def func2(number):
	if number == 1:
		return (-1, 0, 0)
	if number == 2:
		return (-1, 0, 0)
	if number == 3:
		return (0, 0, 1)
	if number == 4:
		return (-1, 0, 0)
	if number == 5:
		return (0, 1, 0)
	if number == 6:
		return (0, 0, 2)
	if number == 7:
		return (1, 0, 0)
	if number == 8:
		return (0, 1, 1)
	if number == 9:
		return (0, 0, 3)
	if number == 10:
		return (0, 2, 0)
	if number == 11:
		return (0, 1, 2)
	if number == 12:
		return (0, 0, 4)
	if number == 13:
		return (0, 2, 1)
	if number == 14:
		return (2, 0, 0)
	if number == 15:
		return (0, 3, 0)
	if number == 16:
		return (0, 2, 2)
	if number == 17:
		return (1, 2, 0)
	if number == 18:
		return (0, 3, 1)
	if number == 19:
		return (0, 3, 3)
	if number == 20:
		return (0, 4, 0)

def func():
	n = int(input())
	n7 = 0
	n5 = 0
	n3 = 0
	if n <= 10:
		(n7, n5, n3) = func2(n)
	else:
		x = n % 10
		y = n // 10
		if x <= 4:
			y = y - 1
			x = x + 10
		(n7, n5, n3) = func2(x)
		n5 = n5 + y * 2
	if n7 == -1:
		print(-1)
		return
	print(n3, n5, n7)
	return

def codeforces1430ProblemB():
	x = [int(i) for i in input().split(' ')]
	n = x[0]
	k = x[1]
	tanks = []
	tanks = [int(i) for i in input().split(' ')]
	tanks = sorted(tanks)
	maxDiff = tanks[n - 1]
	if tanks[n - 1] == 0:
		print(0)
		return
	for i in range(k):
		maxDiff = maxDiff + tanks[n - 1 - (i + 1)]
	print(maxDiff)
	return

def codeforces1430ProblemC():
	n = int(input())
	print(2)
	print(n, n - 1)
	for i in range(n - 2):
		print(n - i, n - (i + 2))
	return
numTest = int(input())
while numTest:
	numTest -= 1
	codeforces1430ProblemC()


import math
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(100000)

def put():
	return map(int, stdin.readline().split())
for _ in range(int(input())):
	n = int(input())
	print(2)
	l = []
	for i in range(n):
		l.append(i + 1)
	print(n - 1, n)
	n -= 2
	for i in range(n):
		print(n, n + 2)
		n -= 1


import sys
import heapq
import copy
import math
import decimal
input = sys.stdin.readline

def binary_exponentiation(a, b):
	ans = 1
	while b != 0:
		bit = b % 2
		if bit == 1:
			ans = ans * a
		a = a * a
		b = b // 2
	return ans

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def insr2():
	s = input()
	s = list(s[:len(s) - 1])
	s = [ord(s[i]) - ord('a') for i in range(len(s))]
	return s

def invr():
	return map(int, input().split())
ans = 0

def pr_list(a):
	print(*a, sep=' ')

def swap(a, b):
	temp = a
	a = b
	b = temp
	return [a, b]

def pri(a, b):
	s = '? ' + str(a) + ' ' + str(b)
	print(s)
	sys.stdout.flush()
result = []

def nCk(arr, itr, k, n):
	if len(arr) == k:
		result.append(arr)
		return
	if len(arr) > k or itr == n + 1:
		return
	nCk(arr + [itr], itr + 1, k, n)
	nCk(arr, itr + 1, k, n)
	return

def nPk(arr, itr, k, n):
	if len(arr) == k:
		result.append(arr)
		return
	if len(arr) > k or itr == n + 1:
		return
	for i in range(len(arr) + 1):
		nPk(arr[0:i] + [itr] + arr[i:len(arr)], itr + 1, k, n)
	nPk(arr, itr + 1, k, n)
	return

def main():
	tests = inp()
	mod = 1000000007
	limit = 10 ** 18
	ans = 0
	stack = []
	arr = []
	heapq.heapify(arr)
	for test in range(tests):
		n = inp()
		if n == 1:
			print(1)
			continue
		if n == 2:
			print(2)
			pr_list([1, 2])
			continue
		print(2)
		ans = n // 2
		arr = [i + 1 for i in range(n)]
		arr.pop(n - 3)
		pr_list([n, n - 2])
		curr = (n + n - 2) // 2
		for i in range(n - 3, -1, -1):
			pr_list([curr, arr[i]])
			curr = (curr + arr[i]) // 2
main()


t = int(input())
for i in range(t):
	n = int(input())
	l = list(range(1, n + 1))
	print(2)
	print(n, n - 1)
	for j in range(n - 2):
		print(n - j, n - j - 2)


import math

def fn(n):
	ans = n
	a = []
	for i in range(n - 1, 0, -1):
		a.append([ans, i])
		ans = math.ceil((ans + i) / 2)
	return (ans, a)
for _ in range(int(input())):
	n = int(input())
	(ans, a) = fn(n)
	print(ans)
	for i in range(len(a)):
		print(*a[i])


from math import ceil
t = int(input())
while t:
	n = int(input())
	st = [i for i in range(1, n + 1)]
	print(2)
	while len(st) > 1:
		a = st.pop()
		b = st.pop()
		c = ceil((a + b) / 2)
		st.append(c)
		print(a, b)
	t -= 1


from sys import stdin, stdout
for _ in range(int(input())):
	n = int(input())
	array = [i for i in range(1, n + 1)]
	arr = []
	x = n - 1
	for _ in range(n - 1):
		arr.append([array[x], array[x - 1]])
		ele = (array[x] + array[x - 1] + 1) // 2
		array.pop()
		array.pop()
		array.append(ele)
		x -= 1
	print(array[0])
	for k in arr:
		print(*k)


import math

def factorial(n):
	if n == 1:
		return 0
	return n * fact(n - 1)
t = int(input())
for z in range(t):
	n = int(input())
	a = [0] * n
	for j in range(n):
		a[j] = j + 1
	x = []
	while len(a) > 1:
		n1 = a.pop()
		n2 = a.pop()
		x.append([n1, n2])
		ans = math.ceil((n1 + n2) / 2)
		a.append(ans)
	print(*a)
	for c in x:
		print(*c)


ans = []
for i in range(int(input())):
	n = int(input())
	z = list(map(int, range(1, n + 1)))
	ans.append('2')
	while len(z) != 2:
		if z[-1] % 2 == 0:
			if z[-2] % 2 == 0:
				ans.append(str(z[-2]) + ' ' + str(z[-1]))
				z.append(round((z.pop(-1) + z.pop(-1)) // 2))
			elif z[-3] % 2 == 0:
				ans.append(str(z[-3]) + ' ' + str(z[-1]))
				z.append(round((z.pop(-1) + z.pop(-2)) // 2))
		elif z[-1] % 2 != 0:
			if z[-2] % 2 != 0:
				ans.append(str(z[-2]) + ' ' + str(z[-1]))
				z.append(round((z.pop(-1) + z.pop(-1)) // 2))
			elif z[-3] % 2 != 0:
				ans.append(str(z[-3]) + ' ' + str(z[-1]))
				z.append(round((z.pop(-1) + z.pop(-2)) // 2))
	ans.append(str(z[-2]) + ' ' + str(z[-1]))
for i in ans:
	print(i)


from math import ceil
n = int(input())
for _ in range(n):
	k = int(input())
	arr = list(range(1, k + 1))
	o = []
	for i in range(k - 1):
		a = arr.pop()
		b = arr.pop()
		o.append((a, b))
		arr.append(ceil((a + b) / 2))
	print(arr[0])
	for i in range(len(o)):
		print(o[i][0], o[i][1])


from sys import stdin
nii = lambda : map(int, stdin.readline().split())
lnii = lambda : list(map(int, stdin.readline().split()))
from math import ceil
t = int(input())
for tt in range(t):
	n = int(input())
	num = n
	l = []
	for i in range(n - 1):
		l.append([num, n - i - 1])
		num = ceil((2 * n - 2 * i - 1) / 2)
	print(num)
	for i in l:
		print(*i)


for _ in range(int(input())):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
	else:
		print(n, n - 2)
		print(n - 1, n - 1)
		i = 0
		som = n - 1
		p = n
		n = n - 3
		while i < p - 3:
			print(som, n)
			som = int((som + n) / 2)
			i += 1
			n = n - 1


t = int(input())
for _ in range(t):
	limit = int(input())
	if limit == 2:
		print(2)
		print(1, 2)
	else:
		print(2)
		print(limit - 2, limit)
		print(limit - 1, limit - 1)
		for i in range(limit - 3, 0, -1):
			print(i, i + 2)


for _ in range(int(input())):
	n = int(input())
	print(2)
	print(n, n - 1)
	while n - 2 >= 1:
		print(n, n - 2)
		n -= 1


import heapq
import math

class Heap:

	def __init__(self) -> None:
		self.heap = list()

	def insert(self, element):
		heapq.heappush(self.heap, -1 * element)

	def pop(self):
		return -1 * heapq.heappop(self.heap)

	def isSingle(self):
		return len(self.heap) == 1
t = int(input())
for _ in range(t):
	n = int(input())
	heap = Heap()
	for i in range(1, n + 1):
		heap.insert(i)
	A = list()
	B = list()
	while not heap.isSingle():
		a = heap.pop()
		b = heap.pop()
		A.append(a)
		B.append(b)
		heap.insert(math.ceil((a + b) / 2))
	print(heap.pop())
	for i in range(len(A)):
		print(A[i], B[i])


def solve(n):
	print(n - 1, n)
	pre = n
	for a in range(n - 2, 0, -1):
		print(a, pre)
		pre = (pre + a + 1) // 2
for _ in range(int(input())):
	n = int(input())
	print(2)
	solve(n)


import math
from collections import deque
from collections import defaultdict
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	print(2)
	if n <= 4:
		if n == 2:
			print(1, 2)
		elif n == 3:
			print(1, 3)
			print(2, 2)
		elif n == 4:
			print(2, 4)
			print(3, 3)
			print(1, 3)
	else:
		print(n, n - 2)
		print(n - 1, n - 1)
		for i in range(n - 3):
			print(n - i - 1, n - i - 3)


import math
import copy
t = int(input())
for _ in range(t):
	n = int(input())
	x = [i for i in range(1, n + 1)]
	print(2)
	k = n - 2
	while x:
		if len(x) == 1:
			break
		a = x.pop()
		b = x.pop()
		print(a, b)
		x.append(math.ceil((a + b) / 2))


t = int(input())
while t:
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	else:
		(a, b, c) = (n, n - 1, n - 2)
		cur = (a + b) // 2 + (a + b) % 2
		print(2)
		while cur > 2:
			print(a, b)
			cur = (a + b) // 2 + (a + b) % 2
			a = cur
			b = c
			c = c - 1
	t -= 1


import math
t = int(input())
for i in range(t):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
	else:
		for i in range(n - 1):
			if i != 1:
				print(n, n - 2)
				n = math.ceil((n + n - 2) / 2)
			else:
				print(n, n)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

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

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

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		n = ri()
		a = deque([])
		for i in range(1, n + 1):
			a.append(i)
		ans = []
		while len(a) > 1:
			(x, y) = (a[-1], a[-2])
			ans.append([x, y])
			c = math.ceil((x + y) / 2)
			a.pop()
			a.pop()
			a.append(c)
		print(2)
		for i in ans:
			print(*i)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


from math import ceil
for _ in range(int(input())):
	n = int(input())
	print(2)
	l = [i for i in range(n, 0, -1)]
	print(l[0], l[1])
	j = ceil((l[0] + l[1]) / 2)
	for i in range(n - 2):
		print(l[i + 2], j)
		j = ceil((l[i + 2] + j) / 2)


import sys, os
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
from time import time
MOD = 998244353

def main():
	for _ in range(int(input())):
		n = int(input())
		if n == 2:
			print(2)
			print(1, 2)
			continue
		print(2)
		print(n - 2, n)
		arr = [i for i in range(1, n - 2)] + [n - 1, n - 1]
		while len(arr) != 1:
			print(arr[-1], arr[-2])
			tem = ceil((arr[-1] + arr[-2]) / 2)
			(arr.pop(), arr.pop())
			arr.append(tem)
main()


from collections import Counter, OrderedDict
from itertools import permutations as perm
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()
for _ in range(t):
	(n,) = gil()
	print(2)
	if n > 2:
		a = list(range(1, n))
		print(n, n - 2)
		print(n - 1, n - 1)
		a.pop()
		a.pop()
		a.append(n - 1)
		while len(a) > 1:
			print(a[-1], a[-2])
			v = math.ceil((a[-1] + a[-2]) / 2)
			a.pop()
			a.pop()
			a.append(v)
	else:
		print(1, 2)


t = int(input())
for tc in range(t):
	n = int(input())
	print(2)
	print(n - 1, n)
	a = n
	b = n - 2
	for i in range(n - 2):
		print(b, a)
		a -= 1
		b -= 1


import math
for _ in range(int(input())):
	n = int(input())
	a = [i + 1 for i in range(n)]
	ans = []
	while len(a) > 1:
		a1 = a.pop()
		a2 = a.pop()
		ans.append([a1, a2])
		a.append(math.ceil((a1 + a2) / 2))
	print(a[0])
	for (i, j) in ans:
		print(i, j)


def solve(n):
	arr = [x for x in range(1, n + 1)]
	pairs = []
	i = n - 1
	while i > 0:
		(a, b) = (arr[i - 1], arr[i])
		pairs.append((a, b))
		arr[i - 1] = (a + b + 1) // 2
		i -= 1
	return (arr[0], pairs)

def main(input_path=0):
	with open(input_path) as f:
		t = int(f.readline().strip())
		for _ in range(t):
			(ans, pairs) = solve(int(f.readline().strip()))
			print(ans)
			for (a, b) in pairs:
				print(a, b)
main()


from copy import copy
from math import inf
from collections import defaultdict, deque

def main():
	for _ in range(int(input())):
		n = int(input())
		print(2)
		print('%d %d' % (n, n - 1))
		y = n
		x = n - 2
		for i in range(n - 2):
			print('%d %d' % (x, y))
			x -= 1
			y -= 1
main()


def main(n):
	mean = n
	temp = n - 1
	res = 0
	print(2)
	while res != 2:
		print(temp, mean)
		res = (mean + temp) // 2 + (mean + temp) % 2
		mean = res
		temp -= 1
	return
n = int(input())
for i in range(n):
	x = int(input())
	main(x)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l = [i for i in range(1, n + 1)]
	print(2)
	for i in range(n - 1, 0, -1):
		print(l[i], l[i - 1])
		num = (l[i] + l[i - 1] + 1) // 2
		l[i - 1] = num


t = int(input())
for j in range(t):
	n = int(input())
	array = list((i for i in range(1, n + 1)))
	print(2)
	for i in range(n - 1, 1, -1):
		print(array[i - 1], array[i])
		array[i - 1] = (array[i - 1] + array[i] + 1) // 2
	print(array[1], array[0])


import math
for _ in range(int(input())):
	n = int(input())
	l = [i for i in range(1, n + 1)]
	res = []
	while l:
		k = l.pop()
		if not l:
			print(k)
			break
		k1 = l.pop()
		res.append([k, k1])
		l.append(math.ceil((k1 + k) / 2))
	for i in res:
		print(*i)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
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')

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		ans = []
		cnt = 0
		if n == 2:
			print(2)
			print(2, 1)
			continue
		if n == 3:
			print(2)
			print(3, 1)
			print(2, 2)
			continue
		if n == 4:
			print(2)
			print(4, 2)
			print(3, 3)
			print(3, 1)
			continue
		ans.append((n, n - 2))
		ans.append((n - 1, n - 1))
		n -= 1
		while n > 2:
			ans.append((n, n - 2))
			n = n - 1
		print(2)
		for j in range(len(ans)):
			print(ans[j][0], ans[j][1])
main()


for i in range(int(input())):
	n = int(input())
	(r, l) = (n, n - 1)
	print(2)
	while l > 0:
		print(r, l)
		r = (r + l + 1) // 2
		l -= 1


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()
for _ in range(int(I1())):
	n = int(I1())
	l = [i + 1 for i in range(n)]
	a = []
	j = n - 1
	for z in range(n - 1):
		a.append([l[j], l[j - 1]])
		x = (l[j] + l[j - 1] + 1) // 2
		l.pop()
		l.pop()
		l.append(x)
		j -= 1
	print(l[0])
	for x in a:
		print(*x)


import collections
for t in range(int(input())):
	n = int(input())
	print(2)
	nums = [i + 1 for i in range(n)]
	cur = nums.pop()
	while len(nums) > 1:
		if cur % 2 == nums[-1] % 2:
			val = nums.pop()
		else:
			val = nums.pop(len(nums) - 2)
		print(val, cur)
		cur += val
		if cur % 2 == 1:
			cur += 1
		cur //= 2
	print(nums[0], cur)


t = int(input())
for _ in range(t):
	n = int(input())
	print(2)
	print('{0} {1}'.format(n - 1, n))
	for k in range(n, 2, -1):
		print('{0} {1}'.format(k - 2, k))


import sys
input = sys.stdin.readline

def solveC(n):
	print(2)
	if n == 2:
		print(1, 2)
		return
	xs = list(range(1, n + 1))
	print(xs[-3], xs[-1])
	xs[-3:] = [n - 1, n - 1]
	while len(xs) > 1:
		print(*xs[-2:])
		xs[-2:] = [(xs[-2] + xs[-1] + 1) // 2]
t = int(input())
for _ in range(t):
	n = int(input())
	solveC(n)


import math
t = int(input())
while t > 0:
	n = int(input())
	a = n
	b = n - 1
	x = n - 1
	print(2)
	while x > 0:
		print('{p} {q}'.format(p=b, q=a))
		c = int(math.ceil((a + b) / 2))
		a = c
		b -= 1
		x -= 1
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	print(2)
	a = n
	b = n - 1
	print(n, n - 1)
	i = n
	j = n - 2
	while i >= 3 or j >= 1:
		print(i, j)
		i -= 1
		j -= 1


import sys
t = int(input().strip())
for a0 in range(t):
	n = int(input())
	print(2)
	l = []
	for i in range(n):
		l.append(i + 1)
	if n == 2:
		print(1, 2)
	elif n == 3:
		print(1, 3)
		print(2, 2)
	else:
		print(l[n - 3], l[n - 1])
		print(l[n - 2], l[n - 2])
		count = n - 3
		for i in range(n - 3):
			print(count, count + 2)
			count -= 1


from collections import deque
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [i for i in range(1, n + 1)]
	q = deque(arr)
	ans = []
	while len(q) > 2:
		(a, b, c) = (q.pop(), q.pop(), q.pop())
		if a & 1 and b % 2 == 0 or (a % 2 == 0 and b & 1):
			q.append(b)
			q.append((a + c) // 2)
			ans.append([a, c])
		else:
			q.append(c)
			q.append((a + b) // 2)
			ans.append([a, b])
	ans.append([q[-1], q[-2]])
	print(2)
	for a in ans:
		print(*a)


for _ in range(int(input())):
	n = int(input())
	print(2)
	if n > 2:
		a = list(range(1, n + 1))
		print(a[-1], a[-3])
		a[-3] = (a[-1] + a[-3]) // 2
		a.pop()
		while len(a) > 1:
			print(a[-1], a[-2])
			a[-2] = (a[-1] + a[-2]) // 2
			a.pop()
	else:
		print(1, 2)


def tran(n):
	an = [[2]]
	an.append([n, n - 1])
	for i in range(0, n - 2):
		an.append([n - i, n - i - 2])
	return an
t = int(input())
ans = []
for i in range(t):
	n = int(input())
	r = tran(n)
	ans.append(r)
for i in ans:
	for j in i:
		print(*j)


from math import ceil
t = int(input())
while t:
	n = int(input())
	h = n
	u = n
	for x in range(n - 1):
		u = ceil((u + n - 1) / 2)
		n -= 1
	print(u)
	u = n = h
	for x in range(n - 1):
		print(u, n - 1)
		u = ceil((u + n - 1) / 2)
		n -= 1
	t -= 1


def recal(n):
	print(2)
	print(n - 1, n)
	r = n
	while r > 2:
		print(r - 2, r)
		r -= 1
t = int(input())
while t > 0:
	recal(int(input()))
	t -= 1


from math import inf, sqrt, floor, ceil
from collections import Counter, defaultdict, deque
from heapq import heappush as hpush, heappop as hpop, heapify as h
from operator import itemgetter
from itertools import product
from bisect import bisect_left, bisect_right
for _ in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	else:
		l = list(range(1, n + 1))
		l.sort()
		ll = []
		ll.append([l[-1], l[-3]])
		a = l.pop(-3)
		b = l.pop()
		l.append((a + b) // 2)
		while n - 2 > 0:
			ll.append([l[-1], l[-2]])
			l[-2] = (l[-1] + l[-2]) // 2
			l.pop()
			n -= 1
		print(*l)
		for i in ll:
			print(i[0], i[1])


for _ in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
		continue
	elif n == 3:
		print(2)
		print(1, 3)
		print(2, 2)
		continue
	ans = []
	ans.append([n, n - 2])
	ans.append([n - 1, n - 1])
	t = n - 1
	while t >= 3:
		ans.append([t, t - 2])
		t -= 1
	print(2)
	for i in ans:
		print(*i)


from sys import stdin
input = stdin.readline
from heapq import heappush, heappop, heapify

def solve():
	n = int(input())
	h = list(range(-1, -n - 1, -1))[::-1]
	res = []
	print(2)
	while len(h) > 1:
		a = heappop(h)
		b = heappop(h)
		res.append(f'{-a} {-b}')
		heappush(h, (a + b) // 2)
	print('\n'.join(res))
t = int(input())
for _ in range(t):
	solve()


from math import ceil
from collections import deque
for _ in range(int(input())):
	n = int(input())
	d = deque()
	arr = []
	for i in range(1, n + 1):
		d.append(i)
	while len(d) != 1:
		a = d[-1]
		b = d[-2]
		arr.append(str(f'{a} {b}'))
		d.pop()
		d.pop()
		d.append(int(ceil((a + b) / 2)))
	print(d.pop())
	for i in arr:
		print(i)


t = int(input())
for i in range(t):
	num = []
	n = int(input())
	k = 0
	if n >= 3:
		print(2)
		for j in range(1, n + 1):
			num.append(j)
		num.append((num[n - 1] + num[n - 3]) / 2)
		print(int(num[n - 3]), int(num[n - 1]))
		num.pop(n - 1)
		num.pop(n - 3)
		while len(num) != 1:
			k += 1
			num.append((num[n - 1 - k] + num[n - 2 - k]) / 2)
			print(int(num[n - 2 - k]), int(num[n - 1 - k]))
			num.pop(n - 1 - k)
			num.pop(n - 2 - k)
	elif n == 2:
		print(2)
		print(1, 2)
	elif n == 1:
		print(1)


t = int(input())
for _ in range(t):
	n = int(input())
	total = n
	ans = []
	for l in range(n - 1, 0, -1):
		ans.append([l, total])
		total = (total + l + 1) // 2
	print(total)
	ans2 = []
	for xx in ans:
		ans2.append(' '.join([str(x) for x in xx]))
	ans3 = '\n'.join(ans2)
	print(ans3)


import math
t = int(input())
for w in range(t):
	n = int(input())
	print(2)
	k = n
	for i in range(n - 1, 0, -1):
		print(i, k)
		k = math.ceil((k + i) / 2)


import io
import os
import sys
import math
import heapq
input = sys.stdin.readline
mod = 10 ** 9 + 7
t = int(input())
for i in range(t):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	elif n == 3:
		print(2)
		print(1, 3)
		print(2, 2)
	elif n == 4:
		print(2)
		print(2, 4)
		print(3, 3)
		print(1, 3)
	else:
		print(2)
		print(n - 2, n)
		print(n - 1, n - 1)
		for j in range(n - 3):
			print(n - 1 - j, n - 3 - j)


import math
for tc in range(int(input())):
	n = int(input())
	i = n
	summ = n
	for i in range(n - 1, 0, -1):
		summ = math.ceil((summ + i) / 2)
	print(summ)
	flag = 0
	i = n
	j = n - 1
	while j >= 1:
		print(i, j)
		if flag == 1:
			i -= 1
		j -= 1
		if j == 0:
			break
		print(i, j)
		flag = 1
		j -= 1
		i -= 1
		if j == 0:
			break


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
	else:
		print(n, n - 2)
		print(n - 1, n - 1)
		for j in range(n - 3):
			print(n - 1 - j, n - 1 - j - 2)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(range(1, n + 1))
	print(2)
	if n == 2:
		print(1, 2)
		continue
	(x, y) = (l[-2], l[-3])
	(l[-2], l[-3]) = (y, x)
	for j in range(n - 1):
		(a, b) = (l[-2], l[-1])
		print(a, b)
		l[-2] = (a + b) // 2
		del l[-1]


from sys import stdin
casos = int(stdin.readline().strip())
for caso in range(casos):
	n = int(stdin.readline().strip())
	print(2)
	print(n, n - 1)
	for i in range(n, 2, -1):
		print(i, i - 2)


from sys import stdin, stdout
from math import gcd
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(range(1, n + 1))
	ans = []
	while len(a) > 2:
		if not a[-1] + a[-2] & 1:
			ans.append((a[-1], a[-2]))
			a[-2] = a[-1] + a[-2] >> 1
			a.pop()
		elif not a[-1] + a[-3] & 1:
			ans.append((a[-1], a[-3]))
			(a[-3], a[-2]) = (a[-2], a[-1] + a[-3] >> 1)
			a.pop()
		else:
			ans.append((a[-2], a[-3]))
			(a[-3], a[-1]) = (a[-1], a[-2] + a[-3] >> 1)
	ans.append((a[0], a[1]))
	print(a[0] + a[1] + 1 >> 1)
	for i in ans:
		print(*i)


import sys
import math, bisect
sys.setrecursionlimit(10 ** 6)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict

def I():
	return int(sys.stdin.readline())

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

def Neo():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(I()):
	n = I()
	H = [-i for i in range(1, n + 1)]
	heapify(H)
	Ans = []
	while len(H) > 1:
		p = heappop(H)
		q = heappop(H)
		Ans += [(-p, -q)]
		if (-p - q) / 2 - (-p - q) // 2 >= 0.5:
			t = math.ceil((-p - q) / 2)
		else:
			t = (-p - q) // 2
		heappush(H, -t)
	print(int(abs(*list(H))))
	for (i, j) in Ans:
		print(int(i), int(j))


import math
for x in range(int(input())):
	n = int(input())
	a = []
	o = []
	e = []
	ans = []
	if n % 2 == 0:
		t = 0
	else:
		t = 1
	for i in range(n):
		if (i + 1) % 2 == 0:
			e.append(i + 1)
		else:
			o.append(i + 1)
	if n:
		for i in range(n - 1):
			if t == 0:
				if len(e) >= 2:
					v1 = e.pop()
					v2 = e.pop()
					v3 = (v1 + v2) // 2
					ans.append((v1, v2))
					if v3 % 2 == 0:
						e.append(v3)
					else:
						o.append(v3)
				elif len(o) >= 2:
					v1 = o.pop()
					v2 = o.pop()
					ans.append((v1, v2))
					v3 = (v1 + v2) // 2
					if v3 % 2 == 0:
						e.append(v3)
					else:
						o.append(v3)
				else:
					if len(e) > 0:
						v1 = e.pop()
					if len(o) > 0:
						v2 = o.pop()
					ans.append((v1, v2))
					v3 = math.ceil((v1 + v2) / 2)
					if v3 % 2 == 0:
						e.append(v3)
					else:
						o.append(v3)
			elif len(o) >= 2:
				v1 = o.pop()
				v2 = o.pop()
				ans.append((v1, v2))
				v3 = (v1 + v2) // 2
				if v3 % 2 == 0:
					e.append(v3)
				else:
					o.append(v3)
			elif len(e) >= 2:
				v1 = e.pop()
				v2 = e.pop()
				v3 = (v1 + v2) // 2
				ans.append((v1, v2))
				if v3 % 2 == 0:
					e.append(v3)
				else:
					o.append(v3)
			else:
				if len(e) > 0:
					v1 = e.pop()
				if len(o) > 0:
					v2 = o.pop()
				ans.append((v1, v2))
				v3 = math.ceil((v1 + v2) / 2)
				if v3 % 2 == 0:
					e.append(v3)
				else:
					o.append(v3)
			if len(o) >= 2 and len(e) >= 2:
				if o[-1] + o[-2] > e[-1] + e[-2]:
					t = 1
				else:
					t = 0
	if len(o) > 0:
		print(o[0])
	else:
		print(e[0])
	for i in ans:
		print(i[0], i[1])


import math as m
import sys
try:
	for t in range(int(sys.stdin.readline())):
		n = int(sys.stdin.readline())
		print(2)
		a = n - 1
		b = n
		for j in range(0, n - 1):
			print(a, b)
			b = m.ceil((a + b) / 2)
			a = b - 2
except EOFError as e:
	pass


import sys
from collections import defaultdict
input = sys.stdin.readline
from math import ceil
for _ in range(int(input())):
	n = int(input())
	lis = list(range(1, n))
	c = n
	res = []
	while True:
		try:
			res.append((c, lis[-1]))
			c = ceil((c + lis[-1]) / 2)
			lis.pop()
		except:
			break
	print(c)
	for i in res:
		print(*i)


t = int(input())
for i in range(t):
	n = int(input())
	a = []
	for i in range(1, n + 1):
		a.append(i)
	k = a.pop()
	print(2)
	while len(a) > 0:
		q = a.pop()
		print(k, q)
		k = int((k + q) / 2) + (k + q) % 2


import math
t = int(input())
for i in range(t):
	n = int(input())
	a = n
	b = n - 1
	print('2')
	for i in range(1, n):
		print(a, b)
		a = (a + b + 1) // 2
		b -= 1


import math
t = int(input())
for test in range(t):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
		continue
	if n == 3:
		print(2)
		print(2, 3)
		print(1, 3)
		continue
	if n % 2 == 0:
		print(2)
		print(n, n - 2)
		i = n - 1
		a = n - 1
		while i >= 2:
			if i == n - 2:
				i -= 1
				continue
			print(a, i)
			a = (a + i + 1) // 2
			i -= 1
		print(1, 3)
	else:
		print(2)
		print(n, n - 2)
		i = n - 1
		a = n - 1
		while i >= 2:
			if i == n - 2:
				i -= 1
				continue
			print(i, a)
			a = (a + i + 1) // 2
			i -= 1
		print(1, 3)


for _ in range(int(input())):
	a = [i for i in range(1, int(input()) + 1)]
	res = []
	while len(a) > 1:
		x = a.pop(-1)
		y = a.pop(-1)
		if (x + y) % 2 == 0:
			a.append((x + y) // 2)
		else:
			a.append((x + y + 1) // 2)
		res.append([x, y])
	print(a[0])
	for i in res:
		print(i[0], i[1])


t = int(input())
c = []
for i in range(t):
	n = int(input())
	c.append(n)
for n in c:
	print(2)
	print(n, n - 1)
	for j in range(n - 2, 0, -1):
		print(j + 2, j)


from collections import *
from itertools import *
from bisect import *

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

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

def main():
	t = inp()
	for _ in range(t):
		n = inp()
		if n == 2:
			print((1 + 2 + 1) // 2)
			print(1, 2)
			continue
		if n == 3:
			print(2)
			print(2, 3)
			print(1, 3)
			continue
		A = [i for i in range(1, n + 1)]
		ans = []
		while len(A) > 3:
			n = len(A)
			if A[n - 1] - A[n - 2] != 1:
				t = A[n - 1] + A[n - 2]
				ans.append([A[n - 1], A[n - 2]])
				if t % 2 != 0:
					t += 1
				t = t // 2
				A[n - 2] = t
				A.pop()
			else:
				t = A[n - 1] + A[n - 3]
				ans.append([A[n - 1], A[n - 3]])
				if t % 2 != 0:
					t += 1
				t = t // 2
				A[n - 3] = t
				A.pop()
		n = len(A)
		t = A[n - 1] + A[n - 2]
		ans.append([A[n - 1], A[n - 2]])
		if t % 2 != 0:
			t += 1
		t = t // 2
		ans.append([1, t])
		t = 1 + t
		t = t // 2 + (t % 2 != 0)
		print(t)
		for i in ans:
			print(*i, sep=' ')
main()


from math import ceil
t = int(input())
for _ in range(t):
	ops = []
	n = int(input())
	l = list(range(1, n + 1))
	while len(l) > 1:
		a = l.pop()
		b = l.pop()
		ops.append((a, b))
		l.append(ceil((a + b) / 2))
	print(l[0])
	for (a, b) in ops:
		print('%s %s' % (a, b))


T = int(input())
for t in range(T):
	N = int(input())
	if N == 2:
		print(2)
		print(1, 2)
	elif N == 3:
		print(2)
		print(1, 3)
		print(2, 2)
	elif N == 4:
		print(2)
		print(2, 4)
		print(3, 3)
		print(3, 1)
	else:
		print(2)
		print(N, N - 2)
		print(N - 1, N - 1)
		for i in range(N - 3, 0, -1):
			print(i, i + 2)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	now = n
	k = 0
	print(2)
	for i in range(n, 1, -1):
		print(now, i - 1)
		now = math.ceil((now + i - 1) / 2)


import math
testes = int(input())
for _ in range(testes):
	totalnumbers = int(input())
	average = totalnumbers
	totalnumbers = totalnumbers - 1
	result = []
	while totalnumbers > 0:
		result += [(totalnumbers, average)]
		average = math.ceil((average + totalnumbers) / 2)
		totalnumbers = totalnumbers - 1
	print(average)
	for tupla in result:
		print(tupla[0], tupla[1])


n = int(input())
for _ in range(n):
	s = int(input())
	print(2)
	print('{} {}'.format(s, s - 1))
	for i in range(s, 2, -1):
		print('{} {} '.format(i, i - 2))


def do():
	from collections import deque
	import math
	q = int(input())
	for _ in range(q):
		n = int(input())
		dat = deque(reversed(list(range(1, n + 1, 1))))
		operation = []
		while len(dat) > 1:
			a = dat.popleft()
			b = dat.popleft()
			x = math.ceil((a + b) / 2)
			dat.appendleft(x)
			operation.append([a, b])
		print(dat.pop())
		for i in range(n - 1):
			(a, b) = operation[i]
			print(a, b)
do()


for _ in range(int(input())):
	n = int(input())
	[i, j, k] = [2 * n - 1, n - 2, 1]
	print(2)
	i >>= 1
	i += k
	print(n, end=' ')
	print(n - 1)
	while j:
		print(i, end=' ')
		print(j)
		r = i + j
		k = r & 1
		r >>= 1
		r += k
		i = r
		j -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	nlist = list(range(1, n + 1))
	print(2)
	if n == 2:
		print('1 2')
	else:
		aux = n - 1
		print('%d %d' % (nlist[aux - 2], nlist[aux]))
		nlist[aux - 2] = (nlist[aux - 2] + nlist[aux]) / 2
		for i in range(2, n):
			aux = n - i
			print('%d %d' % (nlist[aux - 1], nlist[aux]))
			nlist[aux - 1] = (nlist[aux - 1] + nlist[aux]) / 2


from collections import *
from functools import *
import math
L = []

def f(a, b):
	L.append((a, b))
	return math.ceil((a + b) / 2)
t = int(input())
for i in range(t):
	L = []
	n = int(input())
	ans = reduce(f, list(range(1, n + 1))[::-1])
	print(ans)
	for x in L:
		print(x[0], x[1])


def go(n):
	if n == 2:
		print(1, 2)
		return
	print(n - 2, n)
	print(n - 1, n - 1)
	if n == 3:
		return
	i = n - 3
	j = n - 1
	while i > 0:
		print(i, j)
		i -= 1
		j -= 1
T = int(input())
for t in range(T):
	n = int(input())
	print(2)
	go(n)


import math
for tt in range(int(input())):
	n = int(input())
	print(2)
	l = [i for i in range(1, n + 1)]
	l.sort()
	a = n
	while a != 1:
		tmp = l[a - 1]
		tmp2 = l[a - 2]
		print(tmp, tmp2)
		l.pop(a - 1)
		l.pop(a - 2)
		l.append(math.ceil((tmp + tmp2) / 2))
		a -= 1


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
t = sInt()
for _ in range(t):
	n = sInt()
	if n == 2:
		print(2)
		print(1, 2)
	elif n == 3:
		print(2)
		print(3, 2)
		print(3, 1)
	else:
		print(2)
		print(n, n - 2)
		print(n - 1, n - 1)
		for i in range(n - 3):
			print(n - 1 - i, n - 1 - i - 2)


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from math import gcd, log
from collections import Counter
from pprint import pprint

def main():
	n = int(input())
	arr = [*range(1, n + 1)]
	print(2)
	while len(arr) >= 2:
		t = arr[-2]
		if len(arr) >= 3 and arr[-1] % 2 == arr[-3] % 2:
			print(arr[-1], arr[-3])
			print(arr[-2], arr[-2])
			arr.pop()
			arr.pop()
			arr.pop()
			arr.append(t)
		else:
			print(arr[-1], arr[-2])
			t = (arr[-1] + arr[-2]) // 2
			arr.pop()
			arr.pop()
			arr.append(t)
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')
for _ in range(int(input())):
	main()


import sys
import os
from math import sqrt, log, log2, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial, ceil
from copy import copy, deepcopy
from sys import exit, stdin, stdout
from collections import Counter, defaultdict, deque
from itertools import permutations
import heapq
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
mint = lambda : map(int, inp().split())
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : stdout.flush()

def permute(nums):

	def fun(arr, nums, cur, v):
		if len(cur) == len(nums):
			arr.append(cur.copy())
		i = 0
		while i < len(nums):
			if v[i]:
				i += 1
				continue
			else:
				cur.append(nums[i])
				v[i] = 1
				fun(arr, nums, cur, v)
				cur.pop()
				v[i] = 0
				i += 1
		return arr
	res = []
	nums.sort()
	v = [0] * len(nums)
	return fun(res, nums, [], v)

def subsets(res, index, arr, cur):
	res.append(cur.copy())
	for i in range(index, len(arr)):
		cur.append(arr[i])
		subsets(res, i + 1, arr, cur)
		cur.pop()
	return res

def sieve(N):
	root = int(sqrt(N))
	primes = [1] * (N + 1)
	(primes[0], primes[1]) = (0, 0)
	for i in range(2, root + 1):
		if primes[i]:
			for j in range(i * i, N + 1, i):
				primes[j] = 0
	return primes

def bs(arr, l, r, x):
	if x < arr[0] or x > arr[len(arr) - 1]:
		return -1
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	p = int(sqrt(n))
	for i in range(5, p + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def solve():
	n = iinp()
	arr = [i for i in range(1, n + 1)]
	print(2)
	while len(arr) > 1:
		a = arr.pop()
		b = arr.pop()
		c = ceil((a + b) / 2)
		arr.append(c)
		print(b, a)
for _ in range(iinp()):
	solve()


import math
test = int(input())
for _ in range(test):
	n = int(input())
	arr = []
	for i in range(n):
		arr.append(i + 1)
	print(2)
	m = n - 1
	for i in range(n - 1):
		print(arr[m], arr[m - 1])
		a = arr.pop(m)
		b = arr.pop(m - 1)
		c = math.ceil((a + b) / 2)
		arr.append(c)
		m -= 1


from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	l = list()
	ll = list()
	for i in range(1, n + 1):
		l.append(i)
	while len(l) > 1:
		a = l.pop()
		b = l.pop()
		ll.append(a)
		ll.append(b)
		l.append(ceil((a + b) / 2))
	print(*l)
	j = 0
	while j < len(ll):
		print(ll[j], ll[j + 1])
		j += 2


for _ in range(int(input())):
	n = int(input())
	a = n
	b = n - 2
	if n > 3:
		print('2')
		for i in range(1, n + 1):
			if i != 2:
				print(a, b)
				b = (a + b) // 2
				a = n - i
	elif n == 3:
		print('2')
		print(3, 2)
		print(3, 1)
	else:
		print('2')
		print(2, 1)


import random

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

def lcm(a, b):
	return a * b / gcd(a, b)
for _ in range(int(input())):
	n = int(input())
	curr = n
	print(2)
	for i in range(n - 1, 0, -1):
		print(curr, i)
		curr = (curr + i) // 2 + (curr + i) % 2


from sys import stdin
_input = stdin.readline
(_range, _int) = (range, int)

def solution():
	for _ in _range(_int(_input())):
		n = _int(_input())
		print(2)
		if n == 2:
			print(1, 2)
			continue
		print(n - 2, n)
		print(n - 1, n - 1)
		l = n - 1
		for _ in _range(n - 3):
			print(l - 2, l)
			l -= 1
solution()


ts = int(input())

def f(a, b):
	return str(a) + ' ' + str(b)
for t in range(ts):
	n = int(input())
	print(2)
	if n == 2:
		print(f(1, 2))
	else:
		print(f(n, n - 2))
		print(f(n - 1, n - 1))
		for i in range(n - 1, 2, -1):
			print(f(i, i - 2))


from math import ceil
for _ in range(int(input())):
	n = int(input())
	print(2)
	a = [i for i in range(1, n + 1)]
	for _ in range(n - 1):
		x = a.pop()
		y = a.pop()
		print(x, y)
		a.append(ceil((x + y) / 2))


from collections import Counter
import math
import sys
from bisect import bisect, bisect_left, bisect_right
from itertools import permutations

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

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def mod():
	return 10 ** 9 + 7
for i in range(INT()):
	n = INT()
	if n == 2:
		print(2)
		print(1, 2)
	else:
		print(2)
		print(n - 1, n)
		print(n - 2, n)
		for i in range(n - 3):
			print(n - i - 3, n - i - 1)


def main():
	N = int(input())
	if N == 2:
		print(2)
		print(1, 2)
		return
	ans = []
	ans.append(f'{N - 2} {N}')
	ans.append(f'{N - 1} {N - 1}')
	for n in range(N - 3, 0, -1):
		ans.append(f'{n} {n + 2}')
	print(2)
	print('\n'.join(map(str, ans)))
for __ in [0] * int(input()):
	main()


for _ in range(int(input())):
	N = int(input())
	A = list(range(1, N + 1))
	print(2)
	if N == 2:
		print(1, 2)
	else:
		print(A[-3], A[-1])
		A[-3] = (A[-3] + A[-1]) // 2
		for i in range(2, N):
			print(A[-i], A[-i - 1])
			A[-i - 1] = (A[-i] + A[-i - 1]) // 2


from collections import deque
t = int(input())
for _ in range(t):
	n = int(input())
	ans = []
	d = deque([i for i in range(1, n + 1)])
	for i in range(n - 1):
		ans.append((d[-2], d[-1]))
		x = (d[-2] + d[-1] + 1) // 2
		d.pop()
		d.pop()
		d.append(x)
	print(d[0])
	for i in range(n - 1):
		print(*ans[i])


t = int(input())
for _ in range(t):
	n = int(input())
	start = n - 1
	finish = n
	ans = []
	print(2)
	while start > 0:
		print(start, finish)
		finish = (start + finish + 1) // 2
		start -= 1


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		print(2)
		last = n
		for i in range(n - 1, 0, -1):
			print(last, i)
			last = (last + i) / 2
			if last % 1 != 0:
				last += 1
			last = int(last)
main()


for _ in range(int(input())):
	n = int(input())
	l = list(range(1, n + 1))
	t = []
	x = n - 1
	for i in range(n - 1):
		t.append([l[x - 1], l[x]])
		k = l[x - 1] + l[x]
		if k % 2 != 0:
			k += 1
		l[x - 1] = k // 2
		x -= 1
	print(l[0])
	for i in t:
		print(*i)


for _ in range(int(input())):
	n = int(input())
	print(2)
	a = [0] * (n + 5)
	if n == 2:
		print(1, 2)
		continue
	for i in range(1, n + 1):
		a[i] = i
	idx = n
	for i in range(0, n - 1):
		if (a[idx] + a[idx - 1]) % 2 == 0:
			print(a[idx], a[idx - 1])
			a[idx - 1] = (a[idx] + a[idx - 1]) // 2
			idx -= 1
		else:
			print(a[idx], a[idx - 2])
			a[idx - 2] = (a[idx] + a[idx - 2]) // 2
			idx -= 1


def f(a, b):
	return str(a) + ' ' + str(b)
gans = []
for _ in range(int(input())):
	n = int(input())
	gans.append('2')
	gans.append(f(n, n - 1))
	for i in range(n, 2, -1):
		gans.append(f(i, i - 2))
print('\n'.join(gans))


for _ in range(int(input())):
	n = int(input())
	l = [i for i in range(1, n + 1)]
	res = []
	while len(l) != 1:
		j = len(l) - 1
		i = j - 1
		res.append((l[i], l[j]))
		avg = (l[i] + l[j] + 1) // 2
		l.pop()
		l.pop()
		l.append(avg)
	print(l[0])
	for i in res:
		print(i[0], i[1])


import bisect

def move(b):
	if (b[-1] - b[-2]) % 2 == 0:
		x = (b[-1] + b[-2]) // 2
		ans.append((b[-1], b[-2]))
		del b[-2]
		del b[-1]
		b.insert(bisect.bisect_left(b, x), x)
	elif (b[-1] - b[-3]) % 2 == 0:
		x = (b[-1] + b[-3]) // 2
		ans.append((b[-1], b[-3]))
		del b[-3]
		del b[-1]
		b.insert(bisect.bisect_left(b, x), x)
	elif (b[-2] - b[-3]) % 2 == 0:
		x = (b[-2] + b[-3]) // 2
		ans.append((b[-2], b[-3]))
		del b[-3]
		del b[-2]
		b.insert(bisect.bisect_left(b, x), x)
	return b
import math
t = int(input())
for case in range(t):
	n = int(input())
	a = [int(i) for i in range(1, n + 1)]
	ans = []
	while len(a) > 2:
		a = move(a)
	print(math.ceil(sum(a) / 2))
	for item in ans:
		print(*item)
	print(*a)


import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
letters = ascii_letters[:26]
from collections import defaultdict
input = stdin.readline
print = stdout.write
for _ in range(int(input())):
	n = int(input())
	print('2\n')
	have = n
	for i in range(n - 1, 0, -1):
		print(str(i) + ' ' + str(have) + '\n')
		have = (i + have) // 2 + (i + have) % 2


try:
	t = int(input())
	for i in range(t):
		n = int(input())
		l = []
		for j in range(n):
			l.append(j + 1)
		l2 = []
		while len(l) != 1:
			l1 = []
			if (l[n - 1] + l[n - 2]) % 2 == 0:
				res = (l[n - 1] + l[n - 2]) // 2
			else:
				res = (l[n - 1] + l[n - 2] + 1) // 2
			l1.append(l.pop())
			l1.append(l.pop())
			l2.append(l1)
			l.append(res)
			n = n - 1
		print(l[0])
		for j in range(len(l2)):
			print(l2[j][0], end=' ')
			print(l2[j][1])
except:
	pass


t = int(input())
import math
for i in range(t):
	n = int(input())
	matrix = []
	stack = []
	for i in range(1, n + 1):
		stack.append(i)
	while len(stack) != 1:
		x = stack.pop()
		y = stack.pop()
		d = math.ceil((x + y) / 2)
		stack.append(d)
		matrix.append([y, x])
	print(stack[-1])
	for i in range(len(matrix)):
		for j in range(2):
			print(matrix[i][j], end=' ')
		print()


from math import ceil
inp = lambda : int(input())
strl = lambda : list(input().strip())
seq = lambda : list(map(int, input().strip().split()))

def results(n):
	print(2)
	j = n
	for i in range(n - 1, 0, -1):
		print('{} {}'.format(j, i))
		j = ceil((j + i) / 2)

def main():
	t = inp()
	for _ in range(t):
		n = inp()
		results(n)
main()


t = int(input())

def op(a, b):
	if (a + b) % 2 == 1:
		return (a + b + 1) // 2
	else:
		return (a + b) // 2
for _ in range(t):
	n = int(input())
	deb = n
	oper = []
	for i in range(n - 1, 0, -1):
		oper.append((deb, i))
		deb = op(deb, i)
	print(deb)
	for (x, y) in oper:
		print(x, y)


from math import ceil
cases = int(input())
for _ in range(cases):
	n = int(input())
	r = list(range(1, n + 1))
	ops = []
	if n == 1:
		print('1')
	for i in range(n - 1, 0, -1):
		ops.append([r[i], r[i - 1]])
		r[i - 1] = ceil((r[i] + r[i - 1]) / 2)
		del r[i]
	print(int(r[0]))
	for item in ops:
		print('{} {}'.format(item[0], item[1]))


import math
for i in range(int(input())):
	n = int(input())
	left = n
	output = []
	for i in range(n - 1):
		output.append(str(n - 1 - i) + ' ' + str(left))
		left = math.ceil((left + (n - 1 - i)) / 2)
	print(left)
	for i in range(n - 1):
		print(output[i])


t = int(input())
for _ in range(t):
	n = int(input())
	print(2)
	l1 = []
	for i in range(1, n + 1):
		l1.append(i)
	l1.sort(reverse=True)
	print(l1[0], l1[1])
	x = l1[0]
	for i in range(2, n):
		print(x, l1[i])
		x = (x + l1[i]) // 2
	print()


T = int(input())
for _ in range(T):
	n = int(input())
	print(2)
	print(n - 1, n)
	for i in range(n - 2):
		print(n - 2, n)
		n = n - 1


for i in range(int(input())):
	n = int(input())
	print(2)
	a1 = True
	s = [k for k in range(1, n + 1)]
	for j in range(n - 1, 0, -1):
		if n != 2:
			if s[j] != s[j - 1] and a1:
				a1 = False
				print(s[j], s[j - 2])
				s[j - 2] = s[j - 1]
			else:
				print(s[j], s[j - 1])
				s[j - 1] = (s[j] + s[j - 1]) // 2
		else:
			print(1, 2)


class Solution:

	def __init__(self, n):
		self.n = n

	def solve(self):
		ans = self.n
		for i in range(self.n - 1, 0, -1):
			ans = (ans + i + 1) // 2
		print(ans)
		ans = self.n
		for i in range(self.n - 1, 0, -1):
			print('%d %d' % (ans, i))
			ans = (ans + i + 1) // 2
t = int(input())
for _ in range(t):
	n = int(input())
	s = Solution(n)
	s.solve()


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		N = int(input())
		x = []
		for i in range(1, N + 1):
			x.append(i)
		print(2)
		while len(x) >= 2:
			a = x.pop()
			b = x.pop()
			c = -(-(a + b) // 2)
			print(a, b)
			x.append(c)

def __starting_point():
	main()
__starting_point()


t = int(input())
while t > 0:
	n = int(input())
	a = []
	for i in range(1, n + 1):
		a.append(i)
	print(2)
	if n == 2:
		print(1, 2)
	else:
		print(a[n - 3], a[n - 1])
		p = (a[n - 1] + a[n - 3]) // 2
		del a[n - 1]
		del a[n - 3]
		a.append(p)
		n = n - 1
		a.sort(reverse=True)
		i = 0
		while i < n - 1 and n >= 2:
			p = a[i]
			q = a[i + 1]
			a[i] = 0
			a[i + 1] = (p + q) // 2
			i += 1
			print(p, q)
	t = t - 1


def celing(a, b):
	if (a + b) % 2 == 1:
		return (a + b + 1) // 2
	else:
		return (a + b) // 2
noOfTestCases = int(input())
for i in range(noOfTestCases):
	n = int(input())
	a = [x for x in range(n, 0, -1)]
	print(2)
	print(a[0], a[1])
	p = celing(a[0], a[1])
	cnt = 2
	while cnt < n:
		q = a[cnt]
		print(p, q)
		p = celing(p, q)
		cnt += 1


n = int(input())
while n:
	num = int(input())
	print('2')
	print(num, num - 1)
	while num > 2:
		print(num, num - 2)
		num = num - 1
	n -= 1


def main():
	n = int(input())
	if n == 2:
		print('2\n2 1')
		return
	line = '2\n'
	line += str(n) + ' ' + str(n - 2) + '\n'
	line += str(n - 1) + ' ' + str(n - 1) + '\n'
	for i in range(n - 1, 2, -1):
		line += str(i) + ' ' + str(i - 2) + '\n'
	print(line, end='')
t = int(input())
for i in range(t):
	main()


import math

def count(ch):
	mas = []
	temp = ch
	print(2)
	for i in range(1, ch):
		print(temp, ch - i)
		temp = math.ceil((temp + ch - i) / 2)
for i in range(int(input())):
	n = int(input())
	count(n)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

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 dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

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

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(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

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

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

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(moves, n):
	val = (moves + 1) // 2
	rem = moves - val
	sol = (val + 1) * (rem + 1)
	return sol < n

def sortSecond(val):
	return val[1]
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect
import functools as fnt
from decimal import Decimal

def solve():
	n = scanner()
	print(2)
	print(n, n - 1)
	while n > 2:
		print(n, n - 2)
		n -= 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')

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')
t = scanner()
for i in range(t):
	solve()


def solve(n):
	if n == 2:
		print(2)
		print(1, 2)
	else:
		print(2)
		output = []
		if n > 2:
			output.append('%s %s' % (n - 1, n))
		while n > 2:
			output.append('%s %s' % (n, n - 2))
			n -= 1
		print('\n'.join(output))
for _ in range(int(input())):
	n = int(input())
	solve(n)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	v = list(range(1, n + 1))
	print(2)
	for i in range(n, 1, -1):
		print(v[-2], v[-1])
		x = (v[-2] + v[-1] + 1) // 2
		del v[-1]
		del v[-1]
		v.append(x)


import math
for _ in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	else:
		l = n - 1
		l2 = (2 * n - 2) // 2
		f = [[n, n - 2], [n - 1, n - 1]]
		i = n - 3
		while i >= 1:
			f.append([i, l])
			l = math.ceil((i + l) / 2)
			i -= 1
		print(math.ceil((f[-1][0] + f[-1][1]) / 2))
		for i in f:
			print(*i)


from sys import *
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	odds = [*range(1, n + 1, 2)]
	evens = [*range(2, n + 1, 2)]
	(oddCnt, evenCnt) = (n // 2 + n % 2, n // 2)
	l = []
	(x1, x2) = (0, 0)
	while n > 1:
		if oddCnt > evenCnt:
			(x1, x2) = (odds.pop(), odds.pop())
			oddCnt -= 2
		elif evenCnt >= oddCnt and evenCnt > 1:
			(x1, x2) = (evens.pop(), evens.pop())
			evenCnt -= 2
		else:
			(x1, x2) = (odds.pop(), evens.pop())
			(oddCnt, evenCnt) = (oddCnt - 1, evenCnt - 1)
		l.append([x1, x2])
		mean = x1 + x2
		mean = mean // 2 + mean % 2
		if mean % 2:
			odds.append(mean)
			oddCnt += 1
		else:
			evens.append(mean)
			evenCnt += 1
		n -= 1
	ans = sum(l[-1])
	print(ans // 2 + ans % 2)
	for i in l:
		print(*i)


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def get_input(a=str):
	return a(input())

def get_int_input():
	return get_input(int)

def get_input_arr(a):
	return list(map(a, input().split()))

def get_int_input_arr():
	return get_input_arr(int)

def get_avg(num1, num2):
	return (num1 + num2) // 2 if (num1 + num2) % 2 == 0 else (num1 + num2 + 1) // 2

def solve():
	t = get_int_input()
	for _ in range(t):
		n = get_int_input()
		arr = [x for x in range(1, n + 1)]
		cout << 2 << endl
		if n > 2:
			num_1 = arr.pop(-1)
			num_2 = arr.pop(-2)
			cout << num_2 << ' ' << num_1 << endl
			arr.append(get_avg(num_1, num_2))
			while len(arr) > 1:
				num_1 = arr.pop(-1)
				num_2 = arr.pop(-1)
				cout << num_1 << ' ' << num_2 << endl
				arr.append(get_avg(num_1, num_2))
		else:
			cout << arr[0] << ' ' << arr[1] << endl

def main():
	solve()
main()


import math
t = int(input())
while t != 0:
	n = int(input())
	list1 = [i + 1 for i in range(n)]
	print(2)
	print(list1[-1], list1[-2])
	p = list1.pop()
	q = list1.pop()
	list1.append(p)
	while len(list1) > 1:
		p = list1[-1]
		q = list1[-2]
		print(p, q)
		list1.pop()
		list1.pop()
		list1.append((p + q) // 2)
	t -= 1


from math import ceil
for _ in range(int(input())):
	n = int(input())
	last = n
	pre = n - 1
	print('2')
	for i in range(n - 1):
		print(pre, last)
		last = ceil((pre + last) / 2)
		pre -= 1


for _ in range(int(input())):
	n = int(input())
	arr = [i for i in range(1, n + 1)]
	ans = []
	if n == 2:
		print(2)
		print(1, 2)
	else:
		print(2)
		print(n - 2, n)
		arr[n - 3] = (arr[n - 3] + arr[n - 1]) // 2
		arr.pop(-1)
		n -= 1
		while n > 1:
			print(arr[-2], arr[-1])
			arr[-2] = (arr[-2] + arr[-1]) // 2
			n -= 1
			arr.pop(-1)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

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

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

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		if n == 2:
			print(2)
			print(1, 2)
			return
		print(2)
		l = [i for i in range(1, n + 1)]
		print(n, n - 2)
		l.pop(-1)
		l.pop(-2)
		print(n - 1, n - 1)
		for i in range(n - 2):
			print(l[-1], l[-2])
			t1 = l.pop(-1)
			t2 = l.pop(-1)
			l.append((t1 + t2) // 2)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


import math
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in range(1, n + 1)]
	val = []
	for i in range(n - 1):
		a = arr.pop()
		b = arr.pop()
		x = math.ceil((a + b) / 2)
		arr.append(x)
		val.append((a, b))
	print(arr[0])
	for i in val:
		print(i[0], i[1])


t = int(input())

def op(a, b):
	print(a, b)
for _ in range(t):
	n = int(input())
	odd = [i for i in range(1, n + 1, 2)]
	even = [i for i in range(2, n + 1, 2)]
	if n & 1:
		turn = 'odd'
	else:
		turn = 'even'
	if n == 2:
		print(2)
		print(1, 2)
		continue
	print(2)
	while len(odd) + len(even) != 1:
		if turn == 'odd':
			a = odd.pop()
			b = odd.pop()
			op(a, b)
			x = (a + b + 1) // 2
			if len(even) and len(odd):
				turn = 'even' if x != odd[-1] and x != even[-1] else 'deven'
			elif len(even):
				turn = 'even'
			else:
				turn = 'odd'
		elif turn == 'even':
			a = even.pop()
			b = even.pop()
			x = (a + b + 1) // 2
			op(a, b)
			if len(even) and len(odd):
				turn = 'odd' if x != odd[-1] and x != even[-1] else 'dodd'
			elif len(even):
				turn = 'even'
			else:
				turn = 'odd'
		elif turn == 'deven':
			a = even.pop()
			b = even.pop()
			x = (a + b + 1) // 2
			op(a, b)
			turn = 'even'
		elif turn == 'dodd':
			a = odd.pop()
			b = odd.pop()
			x = (a + b + 1) // 2
			op(a, b)
			turn = 'odd'
		if x % 2 == 0:
			even.append(x)
		else:
			odd.append(x)


t = int(input())

def solve():
	a = int(input())
	print(2)
	if a == 2:
		print(2, 1)
	else:
		print(a, a - 1)
		print(a, a - 2)
		for i in range(a - 1, 2, -1):
			print(i, i - 2)
for i in range(t):
	solve()


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

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

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

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

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

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
for _ in range(ii()):
	n = ii()
	if n == 2:
		print(2)
		print(1, 2)
	elif n == 3:
		print(2)
		print(1, 3)
		print(2, 2)
	else:
		print(2)
		print(n - 2, n)
		print(n - 1, n - 1)
		for i in range(n - 3):
			print(n - i - 3, n - i - 1)


t = int(input())
import math
for i in range(t):
	f = 0
	n = int(input())
	l = []
	s = (2 * n - 1) // 2 + 1
	k = [n, n - 1]
	l.append(k)
	for i in range(n - 2, 0, -1):
		k = []
		k.append(s)
		s = math.ceil((s + i) // 2)
		k.append(i)
		l.append(k)
	print(s)
	for x in l:
		print(x[0], x[1])


import math
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [i for i in range(1, n + 1)]
	res = list()
	c = 0
	for i in range(n - 1):
		a = arr[n - 1 - i]
		b = arr[n - 2 - i]
		c = math.ceil((a + b) / 2)
		arr[n - 2 - i] = c
		res.append((a, b))
	print(arr[0])
	for (i, j) in res:
		print(i, j)


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

def brute(n):

	def f(avail, moves):
		x = len(avail)
		if x == 1:
			return (avail[0], list(moves))
		best = 10 ** 18
		bestm = None
		for i in range(1, x):
			for j in range(i):
				navail = list(avail)
				a = navail.pop(i)
				b = navail.pop(j)
				moves.append((a, b))
				navail.append(cd(a + b, 2))
				(sc, m) = f(navail, moves)
				if sc < best:
					(best, bestm) = (sc, m)
				moves.pop()
		return (best, bestm)
	return f(list(range(1, n + 1)), [])
for _ in range(int(input())):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
	elif n == 3:
		print(3, 1)
		print(2, 2)
	else:
		moves = [(n, n - 2), (n - 1, n - 1)]
		for i in range(n - 1, 2, -1):
			moves.append((i, i - 2))
		print('\n'.join((f'{a} {b}' for (a, b) in moves)))


import heapq

def solve():
	n = int(input())
	que = [-(i + 1) for i in range(n)]
	data = []
	heapq.heapify(que)
	for i in range(n - 1):
		x = heapq.heappop(que) * -1
		y = heapq.heappop(que) * -1
		data.append((x, y))
		heapq.heappush(que, -(x + y) // 2)
	print(-que[0])
	for (x, y) in data:
		print(x, y)
	return

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


def nr_on_whiteboard():
	test_cases = int(input())
	for t in range(test_cases):
		n = int(input())
		output = [[n, n - 1]]
		for i in range(n - 2):
			output += [[n, n - 2]]
			n = n - 1
		print(2)
		for x in output:
			print(*x)
nr_on_whiteboard()


import sys
from heapq import *

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def string(s):
	return ''.join(s)

def fori(n):
	return [fi() for i in range(n)]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def cil(n, m):
	return n // m + int(n % m > 0)

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

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

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

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < m and (a[i][j] != '.')

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
while t > 0:
	t -= 1
	n = fi()
	a = []
	for i in range(n):
		a.append(-(i + 1))
	heapify(a)
	ans = []
	while len(a) > 1:
		p1 = heappop(a)
		p2 = heappop(a)
		ans.append([-p1, -p2])
		p = (-p1 - p2 + 1) // 2
		heappush(a, -p)
	print(-a[0])
	for i in ans:
		print(*i)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	print(2)
	x = n
	for i in range(n - 1, 0, -1):
		print(x, i)
		x = (x + i + 1) // 2


def read_int() -> int:
	return int(input())

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

def pos_range(n):
	return range(1, 1 + n)

def test_case():
	n = read_int()
	arr = list(pos_range(n))
	pointer = n - 1
	print(2)
	while pointer != 0:
		maximal = arr[pointer]
		(i, to_add) = next(((i, arr[i]) for i in range(pointer - 1, -1, -1) if arr[i] % 2 == maximal % 2), (pointer - 1, arr[pointer - 1]))
		print(to_add, maximal)
		pointer -= 1
		arr[i] = (to_add + maximal + 1) // 2
for _ in range(read_int()):
	test_case()


import math
t = int(input())
while t > 0:
	n = int(input())
	num_list = []
	c = 1
	while c < n + 1:
		num_list.append(c)
		c = c + 1
	print(2)
	while n - 1 > 0:
		a = num_list.pop()
		b = num_list.pop()
		print(a, ' ', b)
		num_list.append(math.ceil((a + b) / 2))
		n = n - 1
	t = t - 1


import sys
import time
import math
import collections
start_time = time.time()
yes = 'YES'
no = 'NO'

def solve(tc):
	n = int(input())
	a = list()
	for i in range(1, n + 1):
		a.append(i)
	print(2)
	for i in range(n - 1):
		print(a[-1], a[-2])
		x = (a[-1] + a[-2] + 1) // 2
		a.pop()
		a.pop()
		a.append(x)
try:
	t = int(input())
	for i in range(t):
		solve(i)
except EOFError:
	pass
sys.stderr.write('**Time -> %.15f fs\n' % (time.time() - start_time))


from math import sqrt, ceil, gcd
from collections import defaultdict
import heapq

def modInverse(b, m):
	g = gcd(b, m)
	if g != 1:
		return -1
	else:
		return pow(b, m - 2, m)
from itertools import permutations

def solve():
	n = int(input())
	ans = []
	prev = n
	for i in range(n - 1, 0, -1):
		ans.append([prev, i])
		prev = ceil((prev + i) / 2)
	print(prev)
	for (a, b) in ans:
		print(a, b)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	odd = []
	even = []
	pairs = []
	for i in range(1, n + 1, 2):
		odd.append(i)
	for i in range(2, n + 1, 2):
		even.append(i)
	while True:
		while len(odd) > 1 and len(even) > 1:
			if odd[len(odd) - 1] > even[len(even) - 1]:
				op1 = odd.pop()
				op2 = odd.pop()
				res = (op1 + op2) // 2
				pairs.append([op1, op2])
				if res % 2 == 0:
					even.append(res)
				else:
					odd.append(res)
			else:
				op1 = even.pop()
				op2 = even.pop()
				res = (op1 + op2) // 2
				pairs.append([op1, op2])
				if res % 2 == 0:
					even.append(res)
				else:
					odd.append(res)
		if len(odd) > 1:
			op1 = odd.pop()
			op2 = odd.pop()
			res = (op1 + op2) // 2
			pairs.append([op1, op2])
			if res % 2 == 0:
				even.append(res)
			else:
				odd.append(res)
		if len(even) > 1:
			op1 = even.pop()
			op2 = even.pop()
			res = (op1 + op2) // 2
			pairs.append([op1, op2])
			if res % 2 == 0:
				even.append(res)
			else:
				odd.append(res)
		if len(odd) == 1 and len(even) == 1:
			op1 = odd.pop()
			op2 = even.pop()
			res = (op1 + op2) // 2 + 1
			pairs.append([op1, op2])
			if res % 2 == 0:
				even.append(res)
			else:
				odd.append(res)
		if len(odd) == 1 and len(even) == 0:
			op1 = odd.pop()
			print(op1)
			for p in pairs:
				print(p[0], p[1])
			break
		if len(odd) == 0 and len(even) == 1:
			op1 = even.pop()
			print(op1)
			for p in pairs:
				print(p[0], p[1])
			break


t = int(input())
import math

def solve(n):
	size = len(n)
	sol = []
	while size > 1:
		a = n.pop()
		b = n.pop()
		n.append(math.ceil((a + b) / 2))
		size -= 1
		sol.append([str(a), str(b)])
	print(n[0])
	for s in sol:
		print(' '.join(s))
for i in range(t):
	n = int(input())
	solve([i for i in range(1, n + 1)])


for _ in range(int(input())):
	n = int(input())
	s = [i for i in range(1, n + 1)]
	print(2)
	o = 0
	for i in range(n - 1):
		if s[-1] % 2 == 1:
			o = 1
		else:
			o = 0
		if o:
			if len(s) == 2:
				print(s[0], s[1])
				break
			if s[-2] % 2:
				print(s[-2], s[-1])
				s[-2] = (s[-2] + s[-1]) // 2
				s.pop()
			else:
				print(s[-3], s[-1])
				s[-3] = (s[-3] + s[-1]) // 2
				s.pop()
		else:
			if len(s) == 2:
				print(s[0], s[1])
				break
			if s[-2] % 2 == 0:
				print(s[-2], s[-1])
				s[-2] = (s[-2] + s[-1]) // 2
				s.pop()
			else:
				print(s[-3], s[-1])
				s[-3] = (s[-3] + s[-1]) // 2
				s.pop()


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	print(2)
	for j in range(n):
		l.append(j + 1)
	if n > 2:
		n3 = l.pop()
		n2 = l.pop()
		n1 = l.pop()
		print(str(n1) + ' ' + str(n3))
		l.append(n2)
		l.append(n2)
	while len(l) > 1:
		n1 = l.pop()
		n2 = l.pop()
		print(str(n1) + ' ' + str(n2))
		l.append(int((n1 + n2 + 1) / 2))


def main():
	test = int(input())
	while test > 0:
		test -= 1
		n = int(input())
		print(2)
		print(n, n - 1)
		for i in range(n - 2, 0, -1):
			print(i + 2, i)
main()


for _ in range(int(input())):
	n = int(input())
	print(2)
	prev = n
	temp = n - 1
	for i in range(n - 1):
		print(prev, temp)
		prev = (prev + temp + 1) // 2
		temp -= 1


for i in range(int(input())):
	b = int(input())
	if b == 2:
		print(2)
		print(2, 1)
	else:
		print(2)
		print(b, b - 2)
		print(b - 1, b - 1)
		b -= 1
		for j in range(b - 2):
			print(b - j, b - j - 2)


def solve():
	n = int(input().strip())
	print(2)
	if n == 2:
		print(1, 2)
		return
	l = list(range(1, 1 + n))
	initial = False
	while len(l) > 1:
		if initial == False:
			initial = True
			print(l[-1], l[-3])
			x = (l[-1] + l[-3]) // 2
			del l[-1]
			del l[-2]
			l.append(x)
		elif l[-1] == l[-2]:
			print(l[-2], l[-1])
			del l[-1]
		else:
			print(l[-1], l[-2])
			x = (l[-1] + l[-2]) // 2
			del l[-1]
			del l[-1]
			l.append(x)
for _ in range(int(input().strip())):
	solve()


import math
for i in range(int(input())):
	n = int(input())
	l = []
	for i in range(1, n + 1):
		l.append(i)
	y = n
	x = n - 1
	i = 1
	print(2)
	while i < n:
		print(f'{x} {y}')
		x = n - 1 - i
		y = math.ceil((x + y + 1) / 2)
		i += 1


import os
import sys
from io import BytesIO, IOBase
_str = str
BUFSIZE = 8192

def str(x=b''):
	return x if type(x) is bytes else _str(x).encode()

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 inp():
	return sys.stdin.readline()

def mpint():
	return map(int, sys.stdin.readline().split(' '))

def itg():
	return int(sys.stdin.readline())

class Transform(int):

	def __lt__(self, other):
		return self >= other

def ceil_divide_2(x):
	return (x >> 1) + (x & 1)
from heapq import *

def solve():
	n = itg()
	hp = [Transform(i) for i in range(1, n + 1)]
	heapify(hp)
	output = []
	for _ in range(n - 1):
		a = heappop(hp)
		b = heappop(hp)
		heappush(hp, Transform(ceil_divide_2(a + b)))
		output.append((a, b))
	print(hp[0])
	for ans in output:
		print(*ans)
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
for _ in range(itg()):
	solve()


for i in range(int(input())):
	a = int(input())
	g = 0
	print(2)
	for i in range(a):
		if i == a - 1:
			break
		if i == 1:
			g = 1
			print(a - 1, a - 1)
		else:
			print(max(a - 2 - i + g, 1), a - i + g)


from sys import stdin, stdout
input = stdin.readline
from collections import defaultdict as dd
from heapq import heapify, heappush, heappop
import math

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

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

def gets():
	return input()

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

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

def solve():
	for _ in range(geta()):
		n = geta()
		print(2)
		if n == 2:
			print(1, 2)
			continue
		a = list(range(1, n + 1))
		print(a[-1], a[-3])
		a[-3] = a[-2]
		a.pop()
		for i in range(n):
			if len(a) == 1:
				break
			if len(a) == 2:
				print(a[-1], a[-2])
				break
			if len(a) >= 3:
				print(a[-1], a[-2])
				a[-2] = (a[-1] + a[-2] + 1) // 2
				a.pop()
solve()


from math import ceil
for _ in range(int(input())):
	n = int(input())
	x = [i for i in range(1, n + 1)]
	s = []
	while len(x) != 1:
		h = x[-1]
		l = x[-2]
		s.append(str(f'{l} {h}'))
		x.pop()
		x.pop()
		x.append(ceil((h + l) / 2))
	print(x[0])
	print('\n'.join(s))


t = int(input())
for i in range(t):
	n = int(input())
	lst = []
	for i in range(n, 0, -1):
		lst.append(i)
	print(2)
	a = n
	for i in range(1, len(lst)):
		print(f'{a} {lst[i]}')
		a = lst[i - 1]


import sys
t = int(input())
for tc in range(t):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
		continue
	print(n - 2, n)
	print(n - 1, n - 1)
	k = n - 1
	for i in range(n - 3):
		print(k - 2, k)
		k = k - 1


cycles = int(input())
for cycle in range(cycles):
	n = int(input())
	print(2)
	print(n - 1, n)
	n -= 2
	while n >= 1:
		print(n, n + 2)
		n -= 1


for t in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
		continue
	print(2)
	l = [[n, n - 2], [n - 1, n - 1]]
	for i in range(n - 3):
		x = sum(l[-1]) // 2
		l.append([x, x - 2])
	for e in l:
		print(*e)


for _ in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(str(1) + ' ' + str(2))
	else:
		a = n - 2
		(b, k) = (n, n - 1)
		print(2)
		print(str(a) + ' ' + str(b))
		while k != 1:
			if k == n - 1:
				b = (a + b) // 2
				a = n - 1
			elif k == n - 2:
				b = (a + b) // 2
				a = n - 3
			else:
				b = (a + b) // 2
				a = a - 1
			print(str(a) + ' ' + str(b))
			k -= 1


t = int(input())
while t:
	n = int(input())
	print(2)
	print(n, n - 1)
	k = n
	for i in range(n - 2):
		a1 = k
		a2 = k - 2
		k = a1 - 1
		print(a1, a2)
	t = t - 1


for t in range(int(input())):
	n = int(input())
	print(2)
	if n == 2:
		print('1 2')
		continue
	if n == 3:
		print('3 2')
		print('1 3')
		continue
	(a, b) = (n - 1, n - 3)
	print(n, n - 1)
	print(n, n - 2)
	for i in range(n - 3):
		print(a, b)
		a -= 1
		b -= 1


for _ in range(int(input())):
	n = int(input())
	print(2)
	if n == 2:
		print(2, 1)
	else:
		for i in range(n - 1):
			if not i:
				print(n, n - 2)
			elif i == 1:
				print(n - 1, n - 1)
			else:
				print(n + 1 - i, n - 1 - i)


import sys
read = lambda : sys.stdin.readline().strip()
readi = lambda : map(int, read().split())
from collections import *
from math import *
for _ in range(int(read())):
	n = int(read())
	last = n
	print(2)
	for i in range(n - 1, 0, -1):
		print(i, last)
		last = ceil((last + i) / 2)


import math
for _ in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
		continue
	print(2)
	for i in range(n, 2, -1):
		print(i, i - 2)
		if i == n:
			print(i - 1, i - 1)


def sufferu(n):
	print(2)
	if n == 2:
		print(1, 2)
	else:
		print(n, n - 2)
		print(n - 1, n - 1)
		for i in range(n - 3):
			print(n - 1 - i, n - 3 - i)
for _ in range(int(input())):
	sufferu(int(input()))


from __future__ import division
from sys import stdin, stdout
from collections import deque, defaultdict, Counter
rstr = lambda : stdin.readline().strip()
rstrs = lambda : [str(x) for x in stdin.readline().split()]
rint = lambda : int(stdin.readline())
rints = lambda : [int(x) for x in stdin.readline().split()]
rstr_2d = lambda n: [rstr() for _ in range(n)]
rint_2d = lambda n: [rint() for _ in range(n)]
rints_2d = lambda n: [rints() for _ in range(n)]
pr = lambda args, sep: stdout.write(sep.join(map(str, args)) + '\n')
out = []
for _ in range(int(input())):
	n = rint()
	out.append('2')
	if n == 2:
		out.append('1 2')
	else:
		if n & 1:
			out.append('%d %d' % (n, n - 1))
		else:
			out.append('%d %d' % (n, n - 2))
			out.append('%d %d' % (n - 1, n - 1))
			n -= 1
		for i in range(n - 2, 0, -1):
			out.append('%d %d' % (n, i))
			n -= 1
print('\n'.join(out))


from sys import stdin, stdout
import math, bisect
from collections import Counter, deque, defaultdict
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
S = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()

def pr(a):
	return ' '.join(list(map(str, a)))

def solve():
	n = I()
	if n == 2:
		print(2)
		print(2, 1)
	else:
		print(2)
		print(n - 1, n)
		for i in range(n - 2):
			print(n, n - 2)
			n -= 1
for _ in range(I()):
	solve()


for _ in range(int(input())):
	n = int(input())
	arr = [i for i in range(1, n + 1)]
	print(2)
	while len(arr) != 1:
		print(arr[-1], end=' ')
		print(arr[-2])
		x = arr[-1]
		y = arr[-2]
		z1 = (x + y) / 2
		z2 = (x + y) // 2
		if z1 == z2:
			z = z2
		else:
			z = z2 + 1
		arr.pop()
		arr.pop()
		arr.append(z)


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
import threading
import sys
import time

def get_int():
	return int(stdin.readline().strip())

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

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

def solve():
	n = get_int()
	if n == 2:
		print(2)
		print(1, 2)
		return
	print(2)
	print(n - 2, n)
	print(n - 1, n - 1)
	(i, j) = (3, 1)
	while n - i >= 1:
		print(n - j, n - i)
		i += 1
		j += 1

def main():
	solve()
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


import math

def modinv(n, p):
	return pow(n, p - 2, p)

def main():
	for case in range(int(input())):
		n = int(input())
		temp = []
		l = n - 1
		r = n
		for i in range(n - 1):
			temp.append([l, r])
			r = math.ceil((l + r) / 2)
			l -= 1
		print(r)
		for x in temp:
			print(*x)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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()


import math
for _ in range(int(input())):
	n = int(input())
	a = [i for i in range(1, n + 1)]
	r = []
	for i in range(len(a) - 1, 0, -1):
		r.append('%s %s' % (a[i], a[i - 1]))
		a[i - 1] = math.ceil(a[i] / 2 + a[i - 1] / 2)
		a[i] = 0
	print(a[0])
	for i in r:
		print(i)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

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

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

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math
from collections import defaultdict
for _ in range(ri()):
	n = ri()
	wi(2)
	x = n - 1
	y = n
	print(x, y)
	x -= 1
	for i in range(n - 2):
		print(x, y)
		x -= 1
		y -= 1


import math
t = int(input())
while t:
	n = int(input())
	a = [i for i in range(1, n + 1)]
	flag = False
	for i in range(n - 2, -1, -1):
		if not flag:
			print(2)
			flag = True
		print(a[i], a[i + 1])
		a[i] = math.ceil((a[i] + a[i + 1]) / 2)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	arr = [i for i in range(1, n + 1)]
	print(2)
	for i in range(n - 2, -1, -1):
		print(arr[i], arr[i + 1])
		avg = (arr[i] + arr[i + 1]) / 2
		if avg != (arr[i] + arr[i + 1]) // 2:
			avg = int(avg) + 1
		else:
			avg = int(avg)
		arr[i] = avg


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	ar = []
	for i in range(1, n + 1):
		ar.append(i)
	ans = []
	for i in range(n - 1, 0, -1):
		if ar[i] % 2 == ar[i - 1] % 2:
			ans.append([ar[i], ar[i - 1]])
			ar[i - 1] = (ar[i] + ar[i - 1]) // 2
		elif i != 1:
			ans.append([ar[i], ar[i - 2]])
			ar[i - 2] = (ar[i] + ar[i - 2]) // 2
		else:
			ans.append([ar[0], ar[1]])
			ar[0] = (ar[1] + ar[0] + 1) // 2
	print(ar[0])
	for i in ans:
		print(*i)


import math
for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(1, n + 1):
		a.append(i)
	n = n - 1
	print(2)
	while n > 0:
		c = a.pop()
		b = a.pop()
		print(c, b)
		n -= 1
		a.append(math.ceil((c + b) / 2))


for _ in range(int(input())):
	N = int(input())
	print(2)
	for i in range(N - 1, 0, -1):
		print(N, i)
		if (N + i) % 2 == 0:
			N = (N + i) // 2
		else:
			N = (N + i) // 2 + 1


import math
t = int(input())
for _ in range(t):
	n = int(input())
	l = [i for i in range(1, n + 1)]
	ans = []
	while len(l) >= 3:
		last = l.pop()
		if l[len(l) - 1] == last:
			ans.append([last, last])
			continue
		else:
			sec_last = l.pop()
			thir_last = l.pop()
			if (last - sec_last) % 2 == 0:
				ans.append([last, sec_last])
				l.append(thir_last)
				l.append(round((last + sec_last) / 2))
			else:
				ans.append([thir_last, last])
				x = round((thir_last + last) / 2)
				l.append(min(x, sec_last))
				l.append(max(x, sec_last))
	print(round((l[0] + l[-1]) / 2))
	for (i, j) in ans:
		print(i, j)
	del ans
	print(l[0], l[-1])


t = int(input())
for i in range(t):
	n = int(input())
	print(2)
	a = [0] * n
	for i in range(n):
		a[i] = i + 1
	ukazatel = n - 2
	for i in range(n - 1):
		print(a[n - 1], a[ukazatel])
		if (a[n - 1] + a[ukazatel]) % 2 == 0:
			a[n - 1] = (a[n - 1] + a[ukazatel]) // 2
		else:
			a[n - 1] = (a[n - 1] + a[ukazatel]) // 2 + 1
		ukazatel -= 1


import math
t = int(input())
for tt in range(t):
	n = int(input())
	l = [0] * n
	for i in range(n):
		l[i] = i + 1
	temp = []
	while len(l) > 1:
		num_1 = l.pop()
		num_2 = l.pop()
		temp.append([num_1, num_2])
		ans = math.ceil((num_1 + num_2) / 2)
		l.append(ans)
	print(*l)
	for t in temp:
		print(*t)


import sys
readline = sys.stdin.readline
t = int(readline())
for _ in range(t):
	n = int(readline())
	x = n
	print(2)
	for i in range(n - 1, 0, -1):
		print(i, x)
		x = (x + i + 1) // 2


import math
t = int(input())
for _ in range(t):
	n = int(input())
	l = [i for i in range(n, 0, -1)]
	tuplas = [(l[0], l[1])]
	ma = math.ceil((l[0] + l[1]) / 2)
	for i in range(2, n):
		tuplas.append((ma, l[i]))
		ma = math.ceil((ma + l[i]) / 2)
	print(ma)
	for e in tuplas:
		print(f'{e[0]} {e[1]}')


for _ in range(int(input())):
	num = int(input())
	print(2)
	b = num
	print(num, b - 1)
	for i in range(num, 2, -1):
		print(i, b - 2)
		b -= 1


from sys import stdin, stdout
t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	print(2)
	print(n, n - 1)
	ti = n - 2
	while ti > 0:
		ti -= 1
		print(n, n - 2)
		n = n - 1


import os
import sys
from math import *
from collections import *
from bisect 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 = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

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()]
for _ in range(Int()):
	n = Int()
	a = [i + 1 for i in range(n)]
	print(2)
	for i in range(n - 1):
		x = a.pop()
		y = a.pop()
		a.append(Ceil(x + y, 2))
		print(x, y)


import sys

def get_ints():
	return map(int, sys.stdin.readline().split())
for _ in range(int(input())):
	n = int(input())
	arr = [i for i in range(n + 1)]
	if n == 2:
		print(2)
		print(1, 2)
	else:
		print(2)
		print(n, n - 2)
		(a, b) = (n - 1, n - 1)
		i = 1
		while i != n - 2:
			print(a, b)
			(a, b) = ((a + b) // 2, (a + b) // 2 - 2)
			i += 1
		print(a, b)


from math import ceil

def solve():
	x = int(input())
	cur = x
	res = []
	pv = x - 1
	for n in range(x - 1):
		res.append([cur, pv])
		cur = ceil((cur + pv) / 2)
		pv -= 1
	print(cur)
	for n in res:
		print(*n)
for _ in range(int(input())):
	solve()


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	n = I()
	if n == 2:
		print(2)
		print(1, 2)
		continue
	print(2)
	print(n, n - 2)
	print(n - 1, n - 1)
	p = n - 1
	for i in range(n - 3):
		print(p, p - 2)
		p -= 1


import math
t = int(input())
for _ in range(t):
	n = int(input())
	nums = [n - i for i in range(n)]
	to_print = []
	prev = nums[0]
	for i in range(1, n):
		to_print.append((prev, nums[i]))
		prev = math.ceil((prev + nums[i]) / 2)
	print(prev)
	for tp in to_print:
		print(*tp)


for _ in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
		continue
	elif n == 3:
		print(2)
		print(3, 1)
		print(2, 2)
		continue
	ar = [1] * n
	print(2)
	while n > 2:
		if ar[n - 1] == 2:
			print(n, n)
			ar[n - 1] = 0
		else:
			print(n, n - 2)
			ar[n - 1] = 0
			ar[n - 3] = 0
			ar[n - 2] += 1
			n -= 1


from math import *
from bisect import *
from collections import *
from random import *
from decimal import *
from itertools import *
import sys
input = sys.stdin.readline

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

def st():
	return input().rstrip('\n')

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

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	n = inp()
	print(2)
	ha = n
	for i in range(n - 1, 0, -1):
		print(ha, i)
		ha = ceil((ha + i) / 2)


import math

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

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

def inn():
	return int(input())
for _ in range(inn()):
	n = inn()
	if n == 2:
		print(2)
		print(1, 2)
	else:
		print(2)
		print(n, n - 2)
		print(n - 1, n - 1)
		a = [i for i in range(1, n - 2)]
		a += [n - 1]
		ln = len(a)
		for i in range(ln - 1, 0, -1):
			print(a[i], a[i - 1])
			a[i - 1] = math.ceil((a[i] + a[i - 1]) / 2)


t = int(input())
for _ in range(t):
	n = int(input())
	print(2)
	if n == 2:
		print(2, 1)
	elif n == 3:
		print(3, 1)
		print(2, 2)
	elif n == 4:
		print(4, 2)
		print(3, 3)
		print(3, 1)
	else:
		print(n, n - 2)
		print(n - 1, n - 1)
		k = n - 1
		while k - 2 >= 1:
			print(k, k - 2)
			k = k - 1


import bisect
import math
t = int(input())
for _ in range(t):
	n = int(input())
	L = list(range(1, n + 1))
	ans = []
	while len(L) > 1:
		a = L.pop(-1)
		bIndex = len(L) - 1
		for i in range(len(L) - 1, -1, -1):
			if L[i] % 2 == a % 2:
				bIndex = i
				break
		b = L.pop(bIndex)
		ans += [str(a) + ' ' + str(b)]
		result = int(math.ceil((a + b) / 2))
		bisect.insort_left(L, result)
	print(L[0])
	for i in ans:
		print(i)


import math
for i1 in range(int(input())):
	n = int(input())
	print(2)
	start = n - 2
	t = math.ceil((2 * n - 1) / 2)
	print(n, n - 1)
	while start > 0:
		print(t, start)
		t = math.ceil((t + start) / 2)
		start -= 1


def solve():
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
		return
	print(2)
	ans = []
	ans.append([n - 2, n])
	ans.append([n - 1, n - 1])
	for i in range(n - 3, 0, -1):
		ans.append([i, i + 2])
	for i in ans:
		print(*i)

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()
main()


import math
t = int(input())
for i in range(t):
	n = int(input())
	print(2)
	print(n, n - 1)
	c = (2 * n - 1) / 2
	c = math.ceil(c)
	n = n - 2
	while n != 0:
		print(c, n)
		c = (n + c) / 2
		c = math.ceil(c)
		n = n - 1


from math import ceil
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	z = []
	n = int(input()) - 1
	x = n + 1
	while n:
		z.append(f'{n} {x}')
		x = ceil((x + n) / 2)
		n -= 1
	print(x, *z, sep='\n')


def Solve():
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
		return
	steps = []
	steps.append((n - 2, n))
	stack = []
	for i in range(1, n):
		if i == n - 2:
			continue
		stack.append(i)
	stack.append((n + n - 2) // 2)
	while len(stack) > 1:
		x = stack[-1]
		y = stack[-2]
		stack.pop()
		stack.pop()
		stack.append((x + y) // 2)
		steps.append((x, y))
	print(stack[0])
	for step in steps:
		print(step[0], step[1])
for _ in range(int(input())):
	Solve()


import math
from collections import deque
q = int(input())
for _ in range(q):
	n = int(input())
	a_even = deque((x for x in range(2, n + 1, 2)))
	a_no_even = deque((x for x in range(1, n + 1, 2)))
	ans = a_even[-1]
	data = []
	for __ in range(n - 1):
		if len(a_even) > 1 and len(a_no_even) > 0 and (a_even[-1] >= a_no_even[-1]) or (len(a_no_even) == 0 and len(a_even) > 1):
			ans = math.ceil((a_even[-1] + a_even[-2]) / 2)
			data.append([a_even[-1], a_even[-2]])
			a_even.pop()
			a_even.pop()
			if ans % 2 == 0:
				a_even.append(ans)
			else:
				a_no_even.append(ans)
		elif len(a_no_even) > 1:
			ans = math.ceil((a_no_even[-1] + a_no_even[-2]) / 2)
			data.append([a_no_even[-1], a_no_even[-2]])
			a_no_even.pop()
			a_no_even.pop()
			if ans % 2 == 0:
				a_even.append(ans)
			else:
				a_no_even.append(ans)
	if len(a_even) != 0 and len(a_no_even) != 0:
		data.append([a_even[-1], a_no_even[-1]])
		print(math.ceil((a_even[-1] + a_no_even[-1]) / 2))
		for x in data:
			print(*x)
	else:
		print(ans)
		for x in data:
			print(*x)


import sys
import bisect as bi
import math as mt
import collections as cc
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n,) = I()
	temp = list(range(1, n + 1))
	x = temp[-1]
	y = temp[-2]
	i = n - 3
	ans = []
	while i >= 0:
		ans.append([x, y])
		x = mt.ceil((x + y) / 2)
		y = temp[i]
		i -= 1
		if i < 0:
			break
	ans.append([x, y])
	print(mt.ceil((x + y) / 2))
	for i in ans:
		print(*i)


for _ in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	else:
		print(2)
		print(n, n - 2)
		print(n - 1, n - 1)
		a = list(range(1, n))
		for i in range(len(a) - 1, 1, -1):
			print(a[i], a[i] - 2)


from math import ceil
f = lambda a, b: ceil((a + b) / 2)
t = int(input())
for _ in range(t):
	n = int(input())
	s = [x for x in range(1, n + 1)]
	selections = []
	while len(s) > 1:
		a = s.pop()
		b = s.pop()
		selections.append((a, b))
		s.append(f(a, b))
	print(s[0])
	for (a, b) in selections:
		print(a, b)


from math import ceil
for _ in range(int(input())):
	n = int(input())
	print(2)
	ans = n
	for i in range(n, 1, -1):
		print(i - 1, ans)
		ans = ceil((i - 1 + ans) / 2)


import math
t = int(input())
for i in range(t):
	n = int(input())
	print(2)
	atual = n
	for j in range(n - 1, 0, -1):
		print(str(j) + ' ' + str(atual))
		atual = math.ceil((j + atual) / 2)


import math
t = int(input())
for _ in range(0, t):
	n = int(input())
	whiteboard = [i for i in range(1, n + 1)]
	pairs = []
	while len(whiteboard) >= 2:
		a = whiteboard.pop()
		b = whiteboard.pop()
		pairs.append((a, b))
		whiteboard.append(math.ceil((a + b) / 2))
	print(min(whiteboard))
	for pair in pairs:
		print(pair[0], ' ', pair[1])


from collections import deque

def solve(n):
	if n == 2:
		return [(1, 2)]
	q1 = [i for i in range(1, n + 1, 2)]
	q2 = [i for i in range(2, n + 1, 2)]
	dif = 0
	if len(q1) == len(q2):
		(q1, q2) = (q2, q1)
		dif = 1
	a = q1.pop()
	a2 = q1.pop()
	ans = [(a, a2)]
	while True:
		b = (a + a2 + 1) // 2
		if (b + dif) % 2:
			if not q1:
				break
			a = b
			a2 = q1.pop()
			ans.append((a, a2))
		else:
			if not q2:
				break
			a = b
			a2 = q2.pop()
			ans.append((a, a2))
	if q1:
		for ai in q1:
			ans.append((a, ai))
			a += ai + 1
			a //= 2
	if q2:
		for ai in q2:
			ans.append((a, ai))
			a += ai + 1
			a //= 2
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	ans = solve(n)
	print(2)
	for ai in ans:
		print(*ai)


import sys
infile = sys.stdin
next(infile)
for line in infile:
	ans = []
	n = int(line)
	print(2)
	print(n, n - 1)
	for i in range(n - 2):
		print(n - i, n - i - 2)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

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

def fi():
	return float(input())

def si():
	return input()

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

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

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

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

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

def lcm(x, y):
	return x * y // gcd(x, y)
mod = 1000000007

def modInverse(b, m):
	g = gcd(b, m)
	if g != 1:
		return -1
	else:
		return pow(b, m - 2, m)

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def modu(a, b, m):
	a = a % m
	inv = modInverse(b, m)
	if inv == -1:
		return -999999999
	else:
		return inv * a % m
from math import log, sqrt, factorial, cos, tan, sin, radians, floor
import bisect
from decimal import *
getcontext().prec = 8
abc = 'abcdefghijklmnopqrstuvwxyz'
pi = 3.141592653589793

def fn(n):
	c = 0
	while n % 2 == 0:
		c += 1
		n //= 2
	return c

def main():
	for _ in range(ii()):
		n = ii()
		print(2)
		print(n - 1, n)
		for i in range(n - 2):
			print(n - 2, n)
			n -= 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')

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')
main()


import sys
input = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
	else:
		first = True
		for i in range(n, 2, -2):
			print(i, i - 2)
			if first:
				print(i - 1, i - 1)
				first = False
			if i - 3 > 0:
				print(i - 1, i - 3)


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 gcd, ceil

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

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
for _ in range(int(input()) if True else 1):
	n = int(input())
	fu = n
	ans = []
	for i in range(n - 1, 0, -1):
		ans.append([fu, i])
		fu = ceil((fu + i) / 2)
	print(fu)
	for each in ans:
		print(*each)


for _ in range(int(input())):
	n = int(input())
	(ls, l) = ([i for i in range(1, n + 1)], [])
	for i in range(n - 1):
		l.append([ls.pop(-1), ls.pop(-1)])
		ls.append(sum(l[-1]) // 2 + 1 if sum(l[-1]) % 2 else sum(l[-1]) // 2)
	print(*ls)
	print('\n'.join([str(i[0]) + ' ' + str(i[1]) for i in l]))


import sys
inp = sys.stdin.buffer.readline
inar = lambda : list(map(int, inp().split()))
inin = lambda : int(inp())
inst = lambda : inp().decode().strip()
wrt = sys.stdout.write
pr = lambda *args, end='\n': wrt(' '.join([str(x) for x in args]) + end)
enum = enumerate
inf = float('inf')
cdiv = lambda x, y: -(-x // y)
from collections import deque
_T_ = inin()
for _t_ in range(_T_):
	n = inin()
	a = [i for i in range(1, n + 1)]
	ans = []
	while len(a) > 1:
		(p, q) = (a.pop(), a.pop())
		ans.append((p, q))
		a.append(cdiv(p + q, 2))
	pr(a[0])
	for i in ans:
		pr(*i)


def solve():
	n = int(input())
	from math import ceil
	print(2)
	l = n
	i = n - 1
	while i:
		print(l, i)
		l = ceil((l + i) / 2)
		i -= 1
for _ in range(int(input())):
	solve()


for i in range(int(input())):
	n = int(input())
	print(2)
	print(n, n - 1)
	for j in range(0, n - 2):
		print(n, n - 2)
		n = n - 1


import sys
T = int(sys.stdin.readline().strip())
for t in range(0, T):
	n = int(sys.stdin.readline().strip())
	print(2)
	if n == 2:
		print('1 2')
	else:
		print(n - 1, n)
		for i in range(0, n - 2):
			print(n - i, n - i - 2)


from sys import stdin, stdout
cases = int(stdin.readline())
for i in range(cases):
	n = int(stdin.readline())
	stdout.write('2' + '\n')
	if n == 2:
		stdout.write('1 2' + '\n')
		continue
	stdout.write(str(n - 2) + ' ' + str(n) + '\n')
	stdout.write(str(n - 1) + ' ' + str(n - 1) + '\n')
	for j in range(n - 3):
		stdout.write(str(n - j - 3) + ' ' + str(n - j - 1) + '\n')


import math
for _ in range(int(input())):
	n = int(input())
	a = [k for k in range(1, n + 1)]
	a.reverse()
	print(2)
	second_thread = a[0]
	for k in range(1, n):
		print(second_thread, a[k])
		second_thread += a[k]
		second_thread = math.ceil(second_thread / 2)


for _ in range(int(input())):
	n = int(input())
	op = []
	l = n
	k = n - 1
	while k > 0:
		op.append((l, k))
		l = (l + k + 1) // 2
		k -= 1
	print(l)
	for i in op:
		print(*i)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = [x for x in range(1, n + 1)]
	if arr == [1, 2]:
		print(2)
		print(1, 2)
		continue
	print('2')
	while True:
		if arr == [2]:
			break
		if arr[-1] % 2 == 0:
			if arr[-2] % 2 == 0:
				a = arr.pop()
				b = arr.pop()
				arr.append((a + b) / 2)
				print(int(b), int(a))
			else:
				a = arr.pop()
				b = arr.pop()
				c = arr.pop()
				arr.append(b)
				arr.append((a + c) / 2)
				print(int(c), int(a))
		elif arr[-2] % 2 == 0:
			a = arr.pop()
			b = arr.pop()
			c = arr.pop()
			arr.append(b)
			arr.append((a + c) / 2)
			print(int(c), int(a))
		else:
			a = arr.pop()
			b = arr.pop()
			arr.append((a + b) / 2)
			print(int(b), int(a))


t = int(input())
for _ in range(t):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	elif n == 3:
		print(2)
		print(1, 3)
		print(2, 2)
	else:
		print(2)
		print(n, n - 2)
		print(n - 1, n - 1)
		a = n - 1
		b = n - 3
		while b > 0:
			print(a, b)
			(a, b) = ((a + b) // 2, b - 1)


num_inp = lambda : int(input())
arr_inp = lambda : list(map(int, input().split()))
sp_inp = lambda : map(int, input().split())
str_inp = lambda : input()
for s in [*open(0)][1:]:
	n = int(s)
	print(2)
	print(n, n - 1)
	for i in range(n - 2):
		print(n - i, n - i - 2)


import heapq
import math
T = int(input())
for t in range(T):
	n = int(input())
	x = [-i for i in range(1, n + 1)]
	t = []
	heapq.heapify(x)
	for _ in range(n - 1):
		a = heapq.heappop(x)
		b = heapq.heappop(x)
		t.append([-a, -b])
		heapq.heappush(x, math.floor((a + b) / 2))
	print(-x[0])
	for i in t:
		print(*i, sep=' ')


import sys
t = int(input())
while t > 0:
	t -= 1
	n = int(sys.stdin.readline())
	print(2)
	if n == 2:
		print(1, 2)
	else:
		print(n - 1, n)
		for i in range(n - 2):
			print(n - 2 - i, n - i)


import math
for _ in range(int(input())):
	n = int(input())
	if n > 2:
		ans = list()
		t = n - 1
		last = math.ceil((n + n - 2) / 2)
		ans.append([n - 2, n])
		for i in range(n - 2):
			ans.append([t, last])
			last = math.ceil((last + t - 1) / 2)
			if t - 1 != n - 2:
				t = t - 1
			else:
				t = t - 2
		print(last)
		for i in range(len(ans)):
			print(f'{ans[i][0]} {ans[i][1]}')
	else:
		print(2)
		print('1 2')


import math
for i in range(int(input())):
	n = int(input())
	l = [i for i in range(1, n + 1)]
	a = l[-1]
	print(2)
	while n > 1:
		print(a, n - 1)
		a = math.ceil((a + n - 1) / 2)
		n -= 1


from math import ceil

def solve(x):
	if x == 2:
		print(2)
		print(1, 2)
		return None
	print(2)
	left = x - 2
	once = True
	while left > 0:
		print(left, x)
		if once:
			print(x - 1, x - 1)
			once = False
		x -= 1
		left -= 1
T = int(input())
for t in range(T):
	n = int(input())
	solve(n)


t = int(input())
result = []
for _ in range(t):
	n = int(input())
	result.append('2')
	if n == 2:
		result.append('1 2')
		continue
	fist = True
	for m in range(n, 2, -1):
		result.append(f'{m} {m - 2}')
		if fist:
			result.append(f'{m - 1} {m - 1}')
			fist = False
print('\n'.join(result))


a = int(input())
while a:
	n = int(input())
	num = [int(n) for n in range(1, n + 1)]
	length = len(num)
	print(2)
	if n > 2:
		print(int(num[n - 1]), int(num[n - 3]))
		num.append((num.pop(n - 1) + num.pop(n - 3)) / 2)
	else:
		print(int(num[length - 1]), int(num[length - 2]))
	for i in range(n - 2):
		length = len(num)
		print(int(num[length - 1]), int(num[length - 2]))
		num.append((num.pop(length - 1) + num.pop(length - 2)) / 2)
	a = a - 1


from math import *
from cmath import *
from itertools import *
from decimal import *
from fractions import *
for _ in range(int(input())):
	n = int(input())
	(r, l) = (n, n - 1)
	print(2)
	while l > 0:
		print(r, l)
		r = (r + l + 1) // 2
		l -= 1


from math import ceil
t = int(input())
while t:
	n = int(input())
	print(2)
	(a, b) = (n - 1, n)
	print(n - 1, n)
	add = ceil((a + b) / 2)
	for i in range(n - 2, 0, -1):
		print(i, add)
		add = ceil((add + i) / 2)
	t -= 1


import math
for _ in range(int(input())):
	n = int(input())
	print(math.ceil((2 ** n - 1) / 2 ** (n - 1)))
	a = n
	b = n - 1
	print(a, b)
	for z in range(2, n):
		a = math.ceil((a + b) / 2)
		b = n - z
		print(a, b)


testes = int(input())
for _ in range(testes):
	n = int(input())
	print(2)
	if n == 2:
		print('2 1')
		continue
	elif n == 3:
		print('3 1')
		print('2 2')
		continue
	else:
		(a, b) = (n, n - 2)
		print(f'{a} {b}')
		(a, b) = (n - 1, n - 1)
		print(f'{a} {b}')
		(a, b) = (n - 1, n - 3)
		print(f'{a} {b}')
		while b > 1:
			(a, b) = (a - 1, b - 1)
			print(f'{a} {b}')


def solve(n):
	print(2)
	if n == 2:
		print(1, 2)
		return
	print(n - 2, n)
	print(n - 1, n - 1)
	for i in range(n - 1, 2, -1):
		print(i - 2, i)
	return
for _ in range(int(input())):
	n = int(input())
	solve(n)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = [i for i in range(1, n + 1)]
	if n == 2:
		print(2)
		print(1, 2)
	else:
		print(2)
		print(a[-1], a[-3])
		c = a[-1] + a[-3]
		c = c // 2
		a.pop(-1)
		a.pop(-2)
		while a:
			d = a.pop(-1)
			print(c, d)
			c = c + d
			c = c // 2


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')
import math
import bisect
from collections import Counter
import bisect
from collections import deque
for _ in range(int(input())):
	n = int(input())
	print(2)
	val = n - 1
	v2 = n
	for i in range(n - 1):
		print(val, v2)
		v2 = math.ceil((val + v2) / 2)
		val -= 1


from heapq import heappop, heapify, heappush
for _ in range(int(input())):
	n = int(input())
	moves = []
	a = [-x for x in range(1, n + 1)]
	heapify(a)
	while len(a) > 1:
		x = -heappop(a)
		y = -heappop(a)
		moves.append((x, y))
		heappush(a, -((x + y) // 2 + (x + y) % 2))
	print(-a[0])
	for (x, y) in moves:
		print(x, y)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	l = [i for i in range(1, n + 1)]
	temp = []
	while len(l) > 1:
		last1 = l.pop()
		last2 = l.pop()
		temp.append([last1, last2])
		l.append(math.ceil((last1 + last2) / 2))
	print(l[0])
	for i in temp:
		print(*i)


from heapq import heappush as hpush
from heapq import heappop as hpop
from heapq import heapify
t = int(input())
for _ in range(t):
	n = int(input())
	if n == 2:
		print(2)
		print(f'{1} {2}')
	elif n > 2:
		arr = []
		ans = []
		for i in range(1, n):
			if i != n - 2:
				val = -i
				arr.append(val)
		temp = -(n + (n - 2)) // 2
		ans.append((n, n - 2))
		heapify(arr)
		hpush(arr, temp)
		for i in range(n - 2):
			val1 = -hpop(arr)
			val2 = -hpop(arr)
			ans.append((val1, val2))
			temp = -((val1 + val2) // 2)
			hpush(arr, temp)
		if len(arr) == 1:
			print(-arr[0])
			length = len(ans)
			for i in range(length):
				print(f'{ans[i][0]} {ans[i][1]}')


import sys
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	n = inp()
	ara = []
	for i in range(n):
		ara.append(i + 1)
	print(2)
	for i in range(n - 2, -1, -1):
		a = ara[i]
		b = ara[i + 1]
		c = (a + b + 1) // 2
		print(a, b)
		ara[i] = c


import sys
input = sys.stdin.buffer.readline
for _ in range(int(input())):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
	else:
		print(n - 2, n)
		print(n - 1, n - 1)
		x = n - 1
		for i in range(n - 3, 0, -1):
			print(x, i)
			x = (x + i) // 2


import math
t = int(input())
while t:
	t -= 1
	n = int(input())
	print(2)
	(k, las) = (n - 1, n)
	for i in range(n - 1):
		print(k, las)
		las = (las + k + 1) // 2
		k -= 1


from sys import stdin
for _ in range(int(stdin.readline())):
	t = int(stdin.readline())
	if t == 2:
		print(2)
		print(2, 1)
		continue
	print(2)
	print(t, t - 2)
	print(t - 1, t - 1)
	for i in range(t - 1, 2, -1):
		print(i, i - 2)


from math import ceil
for _ in range(int(input())):
	n = int(input())
	o = [0]
	e = [0]
	for i in range(1, n + 1):
		if i % 2 == 0:
			e.append(i)
		else:
			o.append(i)
	l = []
	while len(e) >= 1 and len(o) > 2 or (len(e) > 2 and len(o) >= 1):
		if e[-1] > o[-1]:
			(x, y) = (e.pop(), e.pop())
			l.append([x, y])
			x = (x + y) // 2
			if x % 2:
				o.append(x)
			else:
				e.append(x)
		else:
			(x, y) = (o.pop(), o.pop())
			l.append([x, y])
			x = (x + y) // 2
			if x % 2:
				o.append(x)
			else:
				e.append(x)
	if len(e) == 2 and len(o) == 2:
		(x, y) = (e.pop(), o.pop())
		l.append([x, y])
		e.append(ceil((x + y) / 2))
	if len(o) > 1:
		print(o[-1])
	else:
		print(e[-1])
	for (i, j) in l:
		print(i, j)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	print(2)
	a = [i for i in range(1, n + 1)]
	for i in range(n - 1):
		(val1, val2) = (a.pop(), a.pop())
		a.append(math.ceil((val1 + val2) / 2))
		print(val1, val2)


def solve():
	n = int(input())
	print(2)
	arr = [x for x in range(1, n + 1)]
	while n != 2:
		new = arr[-1]
		if new % 2 == 0:
			for i in range(n - 2, -1, -1):
				if arr[i] % 2 == 0:
					new += arr[i]
					new = new // 2
					print(arr.pop(i), arr.pop())
					arr.append(new)
					break
		else:
			for i in range(n - 2, -1, -1):
				if arr[i] % 2 != 0:
					new += arr[i]
					new = new // 2
					print(arr.pop(i), arr.pop())
					arr.append(new)
					break
		n = len(arr)
	print(arr[0], arr[1])
	return

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


for _ in range(int(input())):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
	elif n == 3:
		print(3, 1)
		print(2, 2)
	else:
		print(n, n - 2)
		print(n - 1, n - 1)
		n -= 1
		while n >= 3:
			print(n, n - 2)
			n -= 1


for i in range(int(input())):
	x = int(input())
	print(2)
	print(x, x - 1)
	for i in range(x - 2):
		print(x, x - 2)
		x = x - 1


import sys
input = sys.stdin.readline
from math import ceil
for _ in range(int(input())):
	n = int(input())
	(a, b) = (n - 1, n)
	store = []
	for i in range(n - 1):
		store.append((a, b))
		b = ceil((a + b) / 2)
		a -= 1
	print(b)
	for i in store:
		print(*i)


from math import ceil
for _ in range(int(input())):
	n = int(input())
	print(2)
	print(n, n - 1)
	average = n
	for i in range(n - 2, 0, -1):
		print(i, average)
		average = ceil((average + i) / 2)


t = int(input())
for _ in range(t):
	n = int(input())
	cur = n
	ans = []
	if n == 2:
		print(2)
		print(*[1, 2])
	else:
		ans.append([cur, cur - 2])
		ans.append([cur - 1, cur - 1])
		cur -= 1
		for i in range(n - 3):
			ans.append([cur, cur - 2])
			cur -= 1
		print(cur)
		for i in range(n - 1):
			print(*ans[i])


import math
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l = []
	for i in range(n):
		l.append(i + 1)
	print(2)
	print(n, n - 1)
	s = n
	s1 = n - 2
	for i in range(n - 2):
		print(s, s1)
		s -= 1
		s1 -= 1


def main():
	import sys
	sys.setrecursionlimit(311111)
	ikimasu = sys.stdin.buffer.readline
	ini = lambda : int(ins())
	ina = lambda : list(map(int, ikimasu().split()))
	ins = lambda : ikimasu().strip()
	t = ini()
	for _ in range(t):
		x = ini()
		print(2)
		index = x
		print(index, index - 1)
		for i in range(x - 2):
			print(index, index - 2)
			index -= 1
main()


from math import ceil
import heapq
for _ in range(int(input())):
	n = int(input())
	arr = [-i - 1 for i in range(n)]
	if n == 2:
		print(2)
		print(1, 2)
	else:
		heapq.heapify(arr)
		ops = []
		while len(arr) >= 2:
			f = -heapq.heappop(arr)
			s = -heapq.heappop(arr)
			x = ceil((f + s) / 2)
			heapq.heappush(arr, -x)
			ops.append([f, s])
		ans = -heapq.heappop(arr)
		print(ans)
		for i in ops:
			print(*i)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
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')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=300006, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
for ik in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
	elif n == 3:
		print(2)
		print(1, 3)
		print(2, 2)
	else:
		print(2)
		print(n, n - 2)
		print(n - 1, n - 1)
		t = 0
		for i in range(n - 3, 0, -1):
			print(i, n - 1 - t)
			t += 1


for t in range(int(input())):
	n = int(input())
	mas = [i + 1 for i in range(n)]
	ans = []
	for i in range(n - 1):
		ans.append([mas[-1], mas[-2]])
		if (mas[-1] + mas[-2]) % 2 == 1:
			mas.append((mas.pop() + mas.pop()) // 2 + 1)
		else:
			mas.append((mas.pop() + mas.pop()) // 2)
	print(*mas)
	for i in ans:
		print(*i)


import sys
import collections
input = sys.stdin.readline
ttt = int(input())
for tt in range(ttt):
	n = int(input())
	a = list(range(1, n + 1))
	if n == 2:
		print(2)
		print(1, 2)
		continue
	print(2)
	print(a[len(a) - 1], a[len(a) - 3])
	av = (a[len(a) - 1] + a[len(a) - 3]) // 2
	a.pop(len(a) - 1)
	a.pop(len(a) - 2)
	a.append(av)
	for i in range(n - 2):
		av = (a[len(a) - 1] + a[len(a) - 2]) // 2
		print(a[len(a) - 1], a[len(a) - 2])
		a.pop(len(a) - 1)
		a.pop(len(a) - 1)
		a.append(av)


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


t = int(input(''))
for _ in range(t):
	n = int(input(''))
	cur = 1
	asi = n
	jabo = n - 2
	ans = []
	arr = [0] * (n + 1)
	arr[asi] = 1
	arr[jabo] = 1
	if n == 2:
		print(2)
		print(1, 2)
		continue
	while cur < n:
		ans.append([asi, jabo])
		asi = (asi + jabo) // 2
		if jabo != asi:
			if arr[asi] == 0:
				jabo = asi
			else:
				jabo = asi - 2
		else:
			jabo = asi - 2
		arr[jabo] = 1
		cur += 1
	sol = ans[len(ans) - 1]
	print((sol[0] + sol[1]) // 2)
	for i in ans:
		print(*i)


def readis():
	return map(int, input().strip().split())
T = int(input())
while T:
	T -= 1
	n = int(input())
	print(2)
	print(n, n - 1)
	for i in range(n - 2, 0, -1):
		print(i, i + 2)


t = int(input())
for _ in range(t):
	n = int(input())
	print(2)
	if n == 2:
		print(1, 2)
	else:
		print(n, n - 2)
		print(n - 1, n - 1)
		x = n - 3
		n = n - 1
		while x > 0:
			print(n, n - 2)
			n = n - 1
			x = x - 1


from math import ceil
t = int(input())
for i in range(t):
	n = int(input())
	chet = 0
	b = []
	for i in range(n - 2):
		b.append([0] * 2)
	a = [int(i) for i in range(1, n + 1)]
	while n != 2:
		if (a[n - 1] + a[n - 2]) % 2 == 0:
			b[chet][0] = a[n - 1]
			b[chet][1] = a[n - 2]
			chet += 1
			a.append(ceil((a[n - 1] + a[n - 2]) / 2))
			del a[n - 1]
			del a[n - 2]
			n -= 1
		else:
			b[chet][0] = a[n - 1]
			b[chet][1] = a[n - 3]
			chet += 1
			del a[n - 3]
			n -= 1
			a[n - 1] = a[n - 2]
	print(ceil((a[n - 1] + a[n - 2]) / 2))
	for i in range(len(b)):
		print(b[i][0], b[i][1])
	print(a[n - 1], a[n - 2])


def solve(n):
	arr = [i for i in range(1, n + 1)]
	j = n - 2
	print('2')
	if n == 2:
		print('2' + ' 1')
		return 0
	for i in range(n - 1, 0, -1):
		if j == i:
			j -= 1
		if (arr[i] + arr[j]) % 2 != 0:
			j -= 1
		print(str(arr[i]) + ' ' + str(arr[j]))
		arr[j] = (arr[i] + arr[j]) // 2
t = int(input())
for i in range(t):
	solve(int(input()))


for test in range(int(input())):
	n = int(input())
	l = list(range(1, n + 1))
	if n == 2:
		print(2)
		print(1, 2)
		continue
	s = []
	t1 = l.pop()
	s.append((t1, l[-2]))
	l[-2] = (l[-2] + t1) // 2
	while len(l) > 1:
		s.append((l[-1], l[-2]))
		l[-2] = (l[-1] + l[-2]) // 2
		l.pop()
	print(l[0])
	for item in s:
		print(item[0], item[1])


T = int(input())
for _ in range(0, T):
	n = int(input())
	print(2)
	num = n
	for i in range(n - 1, 0, -1):
		print(i, num)
		if (num + i) % 2 == 0:
			num = (num + i) // 2


import math
import sys
import collections
import bisect
input = sys.stdin.readline
flush = sys.stdout.flush
readint = lambda : int(input())
readintm = lambda : map(int, input().strip().split())
readintl = lambda : list(map(int, input().strip().split()))
readfloatm = lambda : map(float, input().strip().split())
readfloatl = lambda : list(map(float, input().strip().split()))
readstr = lambda : input().strip()
readstrl = lambda : list(input().strip())
join = lambda x, l: x.join(map(str, l))
print = lambda x: sys.stdout.write(str(x) + '\n')
mod = 1000000007
for _ in range(readint()):
	n = readint()
	print(2)
	if n == 2:
		print('1 2')
	else:
		print(f'{n - 2} {n}')
		print(f'{n - 1} {n - 1}')
		for i in range(n - 3, 0, -1):
			print(f'{i} {i + 2}')


for _ in range(int(input())):
	t = int(input())
	p = t
	print(2)
	for i in range(t - 1):
		print(t - 1 - i, p)
		p = 0 - -(t - 1 - i + p) // 2


t = int(input())
for _ in range(t):
	n = int(input())
	prev = n
	for i in range(n - 1, 0, -1):
		if (prev + i) % 2 == 0:
			prev = (prev + i) / 2
		else:
			prev = (prev + i + 1) / 2
	print(int(prev))
	prev = n
	for i in range(n - 1, 0, -1):
		print(int(prev), int(i))
		if (prev + i) % 2 == 0:
			prev = (prev + i) / 2
		else:
			prev = (prev + i + 1) / 2


from collections import Counter
import string
import math
import sys

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
for _ in range(vary(1)):
	n = vary(1)
	arr = [int(i) for i in range(1, n + 1)]
	print(2)
	i = 0
	for i in range(n - 1):
		print(arr[n - 1 - i], arr[n - 2 - i])
		arr[n - 2 - i] = math.ceil((arr[n - 1 - i] + arr[n - 2 - i]) / 2)


import math
for _ in range(int(input())):
	n = int(input())
	print(2)
	a = n - 1 + 1
	b = n - 1
	print(a, b)
	count = 0
	while b != 1:
		if count == 0:
			b -= 1
			count = 1
		else:
			a -= 1
			b -= 1
		print(a, b)


for _ in ' ' * int(input()):
	a = int(input())
	print(2)
	z = a
	i = a
	i1 = a - 1
	while z - 1:
		print(i, i1)
		f = (i + i1 + 1) // 2
		i = f
		i1 -= 1
		z -= 1


t = int(input())
for i in range(t):
	n = int(input())
	print(2)
	print(n, n - 1)
	for i in reversed(range(2, n)):
		print(i + 1, i - 1)


from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	if n == 2:
		print(2)
		print(1, 2)
		continue
	print(2)
	i = n
	k = i
	m = i - 1
	print(i - 1, i)
	while i > 0:
		s = (k + m) / 2
		s = ceil(s)
		i = i - 1
		if i == 0:
			break
		m = i - 1
		k = s
		if m == 0:
			break
		print(m, s)


from itertools import chain
import sys as _sys

def main():
	t = int(input())
	for i_t in range(t):
		(n,) = _read_ints()
		best_tactic = iter(find_best_tactic(n))
		moves = []
		curr_x = next(best_tactic)
		for x in best_tactic:
			moves.append((curr_x, x))
			curr_x = (curr_x + x) // 2 + (curr_x + x) % 2
		print(curr_x)
		for move in moves:
			print(*move)

def _read_line():
	result = _sys.stdin.readline()
	assert result[-1] == '\n'
	return result[:-1]

def _read_ints():
	return map(int, _read_line().split())

def find_best_tactic(numbers_n):
	assert numbers_n >= 1
	if numbers_n == 1:
		return (1,)
	if numbers_n == 2:
		return (2, 1)
	tactic = chain([numbers_n, numbers_n - 2, numbers_n - 1], reversed(range(1, numbers_n - 2)))
	return tuple(tactic)
main()


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

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

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()
for _ in range(II()):
	n = II()
	print(2)
	print(n - 1, n)
	pre = n
	for a in range(n - 2, 0, -1):
		print(a, pre)
		pre = (pre + a + 1) // 2


from sys import stdin

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

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

def linput():
	return list(map(int, stdin.readline().split()))
t = iinput()
while t:
	t -= 1
	n = iinput()
	if n == 2:
		print(2)
		print(1, 2)
	elif n == 3:
		print(2)
		print(1, 3)
		print(2, 2)
	else:
		print(2)
		flag = True
		while n - 2 != 1:
			print(n, n - 2)
			if flag:
				print(n - 1, n - 1)
				flag = False
			n -= 1
		print(n, n - 2)


for _ in range(int(input())):
	n = int(input())
	l = [i for i in range(1, n + 1)]
	print(2)
	if n != 2:
		print(n - 2, n)
		l.pop()
		l[-2] = n - 1
		while l != [2]:
			a = l[-1] + l[-2]
			print(l[-1], l[-2])
			l.pop()
			l[-1] = round(a / 2)
	else:
		print(2, 1)


t = int(input())
for l in range(0, t):
	n = int(input())
	print(2)
	zc = 0
	if n > 2:
		for i in range(n, 0, -1):
			if i == n - 2:
				continue
			if zc == 0:
				print('%d %d' % (i, i - 2))
				zc = i - 1
			else:
				print('%d %d' % (zc, i))
				zc = (i + zc) // 2
	else:
		print('1 2')