Computer Network

All submissions for this problem are available.
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 computertocomputer 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 (N1) 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 spaceseparated 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 spaceseparated 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.
Author:  xcwgf666 
Tester:  pavel1996 
Editorial  http://discuss.codechef.com/problems/EXNETWRK 
Tags  construction, easymedium, ltime31, xcwgf666 
Date Added:  29102015 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 