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

Solutions:
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])


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


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


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


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)


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


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


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


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


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)


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


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)


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)


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)


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)


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


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)


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


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


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


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)


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


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)


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


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


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


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


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


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


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)


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)


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


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)


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


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


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


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


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


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


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


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


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)


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


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


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)


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


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)


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)


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


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


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)


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


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)


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


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


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)


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


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


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


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


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


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


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


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


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


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


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


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


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


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)


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


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


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


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


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]


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


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


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


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


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)


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


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


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)


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)


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)


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


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


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)


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)


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)


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


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)


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)