Centeroid

All submissions for this problem are available.
Read problems statements in mandarin chinese, russian and vietnamese as well.
Chef Ada loves trees, she thinks that the beauty of a tree is determined by the distance between its center and centroid. If the tree has multiple centers or centroids, then the beauty is the maximum among every possible pair.
As a reward for her delicious dishes (and awesome coding skills), CodeChef is going to give a present to Chef Ada, and of course it must be a tree! But not any tree, we want to give her one with n nodes, and beauty b. Help find such a tree.
Input
The first line of input contains one number T, the number of test cases.
Each test case contains two integers n and b, the desired number of vertices and beauty.
Output
For each test case, if no tree satisfies the conditions print "NO" in a new line.
Otherwise, print "YES" in a new line and describe any valid tree. Print n1 more lines, each with two integers u_{i}, v_{i} (1 ≤ u_{i}, v_{i} ≤ n) denoting the indices of the vertices connected by an edge in the tree.
Constraints
Notes
A vertex u is a centroid if after removing u from the tree, the size of any of the resulting connected components is at most n/2.
Lef f(x) be the greatest distance from u to any other vertex of the tree. A vertex u is a center if f(u) ≤ f(v) for any other vertex v.
Example
Input: 1 4 0 Output: YES 1 2 1 3 1 4
Explanation
Vertex 1 is the center and centroid of the tree.
Author:  alei 
Tester:  deadwing97 
Editorial  https://discuss.codechef.com/problems/CENTREE 
Tags  adhoc, alei, constructive, cook83, graph, tree 
Date Added:  30052017 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, 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, 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. 