Read problems statements in Mandarin Chinese , Russian and Vietnamese as well. 

You have been appointed as the designer for your school's computer network.

In total, there are N computers in the class, and M computer-to-computer connections need to be made. Also, there are three mandatory conditions the design should fulfill.

The first requirement is that any computer in the network should be able to communicate with any other computer through the connections, possibly, through some other computers.

Network attacks are possible, so the second requirement is that even if any one computer from the network gets disabled so that the rest of the computers are unable to communicate with it, the rest of the computers can still communicate with each other. In other words, the first requirement still holds for any subset of (N-1) computers.

The third requirement is that there shouldn't be any irrelevant connections in the network. We will call a connection irrelevant if and only if after its' removal, the above two requirements are still held.

Given N, M, please build a network with N computers and M connections, or state that it is impossible.

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

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.

The first and only line of each test case contains a pair of space-separated integers N and M denoting the number of computers and the number of connections.

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

Output T blocks.
If it is impossible to construct a network with the given parameters for the corresponding test case, output just -1 -1. Otherwise, output M lines, each of which contains a space-separated pairs of integers denoting the IDs of the computers that should be connected. Note that multiple connections between any pair of computers and connections connecting a computer to itself are implicitly not allowed due to the third requirement.

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

$1 ≤ T ≤ 1000$
$1 ≤ M ≤ N * (N - 1) / 2$
$1 ≤ Sum of all N ≤ 1000$
$Subtask 1 (21 point): 1 ≤ N ≤ 4$
$Subtask 2 (79 points): 1 ≤ N ≤ 100$

------ Example ------ 

Input:
2
10 1
5 5

Output:
-1 -1
1 2
2 3
3 4
4 5
5 1

------ Explanation ------ 

Example case 1. There are not enough connections even to satisfy the first requirement.
Example case 2. The obtained network satisfies all the requirements.

Difficulty: VERY_HARD
Tags: Graph algorithms

Graph traversal

Constructive algorithms

Starter code:

Solutions:
t = int(input())
for i in range(t):
	(n, m) = [int(x) for x in input().split()]
	if m < n:
		print('-1 -1')
		continue
	if n == 2:
		print('-1 -1')
	elif n == 3 or n == 4:
		if n == m:
			for i in range(1, n):
				print(i, ' ', i + 1)
			print(n, ' ', 1)
		else:
			print('-1 -1')
	else:
		diff = n - 4
		omen = diff + n
		if m > omen:
			print('-1 -1')
		else:
			temp = m - n
			temp = n - temp
			for i in range(1, temp):
				print(i, ' ', i + 1)
			print(temp, ' ', 1)
			if m - n:
				for i in range(temp + 1, n + 1):
					print(i, ' ', 1)
					print(i, ' ', 3)


T = int(input())
for i in range(T):
	(N, M) = map(int, input().split())
	if M < N - 1:
		print(-1, -1)
	elif M == N:
		for j in range(1, N):
			print(j, j + 1)
		print(N, 1)
	else:
		x = M - N + 1
		y = 2 * N - M - 3
		if x > 0 and y > 0:
			length = 2 * (N - 2) - M + 4
			for j in range(1, length):
				print(j, j + 1)
			print(length, 1)
			for j in range(length + 1, N + 1):
				print(1, j)
				print(2, j)
		else:
			print(-1, -1)


t = int(input())
for i in range(t):
	(n, m) = [int(x) for x in input().split()]
	if m < n:
		print('-1 -1')
	elif n == 2:
		print('-1 -1')
	elif n == 3 or n == 4:
		if n == m:
			for i in range(1, n):
				print('%d %d' % (i, i + 1))
			print('%d %d' % (n, 1))
		else:
			print('-1 -1')
	elif n > 4:
		diff = n - 4
		mac = n + diff
		if m > mac:
			print('-1 -1')
		else:
			temp = m - n
			temp = n - temp
			for i in range(1, temp):
				print('%d %d' % (i, i + 1))
			print('%d %d' % (temp, 1))
			if m - n:
				for i in range(temp + 1, n + 1):
					print('%d %d' % (i, 1))
					print('%d %d' % (i, 3))