You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.

Find $\frac{n}{2}$ pairs of elements such that:

Each element in the set is in exactly one pair.

The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation.

If there are many solutions, print any of them, if there is no solution, print $-1$ instead.


-----Input-----

The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows.

Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$).

The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different.


-----Output-----

For each test case, if there is no solution, print a single line with the integer $-1$.

Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair.

If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.


-----Examples-----

Input
4
4 0
4 1
4 2
4 3
Output
0 3
1 2
0 2
1 3
0 1
2 3
-1


-----Note-----

In the first test, $(0\&3)+(1\&2) = 0$.

In the second test, $(0\&2)+(1\&3) = 1$.

In the third test, $(0\&1)+(2\&3) = 2$.

In the fourth test, there is no solution.

Difficulty: MEDIUM

Solutions:
def c(n, i):
	return n - i - 1

def solve(n, k):
	if k == 0:
		for i in range(n // 2):
			print(i, c(n, i))
	elif k < n - 1:
		ignore = [0, k, c(n, k), n - 1]
		print(0, c(n, k))
		print(k, n - 1)
		for i in range(n // 2):
			if i in ignore:
				continue
			print(i, c(n, i))
	elif n == 4:
		print(-1)
	else:
		print(0, 2)
		print(1, n - 3)
		print(n - 1, n - 2)
		for i in range(3, n // 2):
			print(i, c(n, i))
for case in range(int(input())):
	(n, k) = map(int, input().split())
	solve(n, k)


def solve():
	(n, k) = map(int, input().split())
	if n == 4 and k == 3:
		print(-1)
		return
	if k == 0:
		for i in range(n // 2):
			print(i, n - i - 1)
	elif k == n - 1:
		print(0, n - 4)
		print(1, 3)
		print(2, n - 3)
		print(n - 2, n - 1)
		for i in range(4, n // 2):
			print(i, n - i - 1)
	else:
		print(0, n - k - 1)
		print(k, n - 1)
		for i in range(1, n // 2):
			if i != k and i != n - k - 1:
				print(i, n - i - 1)
tst = int(input())
for tt in range(tst):
	solve()


T = int(input())
for k in range(T):
	(n, k) = map(int, input().split())
	if n == 4 and k == 3:
		print(-1)
	elif k == 0:
		for i in range(n // 2):
			print(i, n - i - 1)
	elif k == n - 1:
		print(0, n - 4)
		print(1, 3)
		print(2, n - 3)
		print(n - 2, n - 1)
		for i in range(4, n // 2):
			print(i, n - i - 1)
	else:
		print(0, n - k - 1)
		print(k, n - 1)
		for i in range(1, n // 2):
			if i != k and i != n - k - 1:
				print(i, n - i - 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k == n - 1 and n == 4:
		print(-1)
	elif k == n - 1:
		lis = []
		for i in range(n // 2):
			lis.append((i, n - 1 - i))
		lis[0] = (n - 2, n - 1)
		lis[1] = (0, n - 3 - 1)
		lis[3] = (1, 3)
		for j in lis:
			print(*j)
	else:
		lis = []
		for i in range(1, n // 2):
			lis.append((i, n - 1 - i))
		lis = [(0, n - k - 1)] + lis
		if k == 0:
			pass
		elif k >= n // 2:
			lis[n - k - 1] = (k, n - 1)
		else:
			lis[k] = (k, n - 1)
		for j in lis:
			print(*j)


import sys
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())
t = inp()
for _ in range(t):
	[n, k] = inlt()
	if k >= n:
		print(-1)
		continue
	elif k == 0:
		for i in range(n // 2):
			print(i, n - 1 - i)
	elif k < n - 1:
		ck = n - 1 ^ k
		print(0, ck)
		print(k, n - 1)
		for i in range(n // 2):
			if i == k or i == ck or i == 0:
				continue
			print(i, n - 1 - i)
	elif n == 4:
		print(-1)
	else:
		print(0, 2)
		print(n - 1, n - 2)
		print(1, n - 3)
		for i in range(3, n // 2):
			print(i, n - 1 - i)


def func():
	(n, k) = map(int, input().split())
	a = [0 for i in range(n // 2)]
	b = [0 for i in range(n // 2)]
	if k == 0:
		for i in range(n // 2):
			(a[i], b[i]) = (i, i ^ n - 1)
	elif k > 0 and k < n - 1:
		itr = min(k, k ^ n - 1)
		for i in range(n // 2):
			if i != 0 or i != itr:
				(a[i], b[i]) = (i, i ^ n - 1)
		(a[0], b[0]) = (0, k ^ n - 1)
		(a[itr], b[itr]) = (k, n - 1)
	else:
		if n == 4:
			print(-1)
			return
		(a[0], b[0]) = (n - 2, n - 1)
		(a[1], b[1]) = (1, n - 3)
		(a[2], b[2]) = (0, 2)
		for i in range(3, n // 2):
			(a[i], b[i]) = (i, i ^ n - 1)
	for i in range(n // 2):
		print(a[i], b[i])
t = int(input())
for i in range(t):
	func()


import random

def tInt():
	n = int(input())
	return n

def tList():
	a = map(int, input().split())
	return a

def tStr():
	s = input()
	return s

def solve():
	for _ in range(tInt()):
		(n, k) = tList()
		flag = False
		if n == 4 and k == 3 or k >= n:
			flag = True
			print(-1)
		elif k == 0:
			pair = []
			for i in range(n // 2):
				pair.append([i, n - 1 - i])
		elif k > 0 and k < n - 1:
			pair = []
			small_k = min(k, n - 1 - k)
			for i in range(0, n // 2):
				if i != 0 and i != small_k:
					pair.append([i, n - 1 - i])
			pair.append([0, n - 1 - k])
			pair.append([k, n - 1])
		elif k == n - 1:
			pair = []
			pair.append([n - 2, n - 1])
			pair.append([1, n - 3])
			pair.append([0, 2])
			for i in range(3, n // 2):
				pair.append([i, n - 1 - i])
		if flag == False:
			for (x, y) in pair:
				print(x, y)
solve()


import sys

def solution(n, k):
	if k != n - 1:
		for i in range(n // 2):
			if i == 0:
				print(i, n - k - 1)
			elif i == k:
				print(i, n - 1)
			elif i == n - k - 1:
				print(k, n - 1)
			else:
				print(i, n - i - 1)
		return
	if n <= 4:
		print(-1)
		return
	else:
		for i in range(n // 2):
			if i == 0:
				print(0, 2)
			elif i == 1:
				print(1, n - 3)
			elif i == 2:
				print(n - 1, n - 2)
			else:
				print(i, n - i - 1)
	return
t = None
a = []
b = []
input = sys.stdin.read().splitlines()
t = int(input[0])
offset = 1
for test in range(t):
	data = input[test + offset].split(' ')
	n = data[0]
	k = data[1]
	solution(int(n), int(k))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k == n - 1:
		if n == 4:
			print(-1)
			continue
		print(0, 2)
		print(1, n - 3)
		for i in range(3, n // 2):
			print(i, n - i - 1)
		print(k, k - 1)
		continue
	use = [False] * n
	for i in range(n):
		if use[i]:
			continue
		if i == 0:
			print(i, n - k - 1)
			use[i] = use[n - k - 1] = True
		elif i == k:
			print(i, n - 1)
			use[i] = use[n - 1] = True
		else:
			print(i, n - i - 1)
			use[i] = use[n - i - 1] = True


t = int(input())
while t:
	t = t - 1
	(n, k) = list(map(int, input().split()))
	a = [1] * n
	if k == n - 1:
		if n == 4:
			print(-1)
			continue
		p = 0
		l1 = []
		l2 = []
		while 2 ** p < n:
			l1 += [2 ** p]
			l2 += [n - 1 - 2 ** p]
			p = p + 1
		l1 = l1[1:] + l1[:1]
		for i in range(p):
			print(l1[i], l2[i])
			a[l1[i]] = 0
			a[l2[i]] = 0
		for i in range(n):
			if a[i]:
				j = n - 1 - i
				print(i, j)
				a[j] = 0
		continue
	k2 = n - 1 - k
	if k:
		print(0, k2)
	print(k, n - 1)
	a[0] = 0
	a[k] = 0
	a[k2] = 0
	a[n - 1] = 0
	for i in range(n):
		if a[i]:
			j = n - 1 - i
			print(i, j)
			a[j] = 0


import math
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k == n - 1 and n - 1 == 3:
		print(-1)
		continue
	l = []
	for i in range(n // 2):
		l.append([i, n - 1 - i])
	if k != 0 and k != n - 1:
		id = min(k, n - 1 - k)
		l[0] = [0, n - 1 - k]
		l[id] = [k, n - 1]
	if k == n - 1:
		l[0][0] = n - 2
		l[1][1] = l[-1][0]
		l[-1][0] = 0
	for i in range(len(l)):
		print(*l[i])


for t in range(int(input())):
	(n, k) = map(int, input().split())
	if k == n - 1 and n == 4:
		print(-1)
		continue
	used = set()
	if k == n - 1:
		for i in range(n - 1):
			if i in used:
				continue
			if i == 0:
				print(i, n - 1 - 3)
				used.add(n - 1 - 3)
			elif i == 1:
				print(i, 3)
				used.add(3)
			elif i == n - 2:
				print(n - 1, n - 2)
				used.add(n - 2)
			else:
				print(i, n - 1 - i)
				used.add(n - 1 - i)
	else:
		for i in range(n):
			if i in used:
				continue
			if i == 0:
				print(i, n - 1 - k)
				used.add(n - 1 - k)
			elif i == k:
				print(i, n - 1)
				used.add(n - 1)
			else:
				print(i, n - 1 - i)
				used.add(n - 1 - i)


test_case = int(input())
for i in range(test_case):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	isvisited = set()
	i = 0
	if k == n - 1:
		if n == 4:
			print(-1)
		else:
			k -= 1
			while i < n:
				if i in isvisited:
					i += 1
				else:
					isvisited.add(i)
					if i == 0:
						print(i, n - 1 - 3)
						isvisited.add(n - 1 - 3)
					elif i == 1:
						i += 1
					elif i == 3:
						print(i, 1)
						isvisited.add(1)
					elif i == k:
						print(i, n - 1)
						isvisited.add(n - 1)
					else:
						print(i, n - 1 - i)
						isvisited.add(n - 1 - i)
	else:
		while i < n:
			if i in isvisited:
				i += 1
			else:
				isvisited.add(i)
				if i == 0:
					print(i, n - 1 - k)
					isvisited.add(n - 1 - k)
				elif i == k:
					print(i, n - 1)
					isvisited.add(n - 1)
				else:
					print(i, n - 1 - i)
					isvisited.add(n - 1 - i)