Diameter Two
시간 제한2초메모리 제한512 MB
신뢰할 수 없는 노드는 차수가 정확히 1, 신뢰하는 노드는 차수가 2 이상이 되도록 연결하고 지름이 2 이하가 되게 하면서 간선 수를 최소로 만든다.
문제
You are building a computer network for a new company. The network consists of nodes numbered from to . The nodes can be connected via bidirectional wires. Each wire connects exactly two nodes. Each pair of nodes can be connected with at most one wire. If a wire connects two nodes, we'll say that these two nodes are directly connected.
The first nodes (with indices ) will be untrusted and must be connected to the network securely. Each of these nodes must be directly connected to exactly one other node.
The remaining nodes (with indices ) will be trusted and must be connected to the network reliably. Each of these nodes must be directly connected to at least two other nodes.
The diameter of the network must not exceed : for any two nodes and , they must either be directly connected, or there must exist a node such that nodes and are directly connected, and nodes and are directly connected.
To minimize the costs, the number of used wires must be as small as possible.
Build a network satisfying all the conditions above, or report if this is impossible.
입력
Each test contains multiple test cases. The first line contains the number of test cases (). Description of the test cases follows.
The only line of each test case contains two integers and , denoting the total number of nodes and the number of untrusted nodes, respectively (; ).
출력
For each test case, if it is impossible to build a network satisfying the given conditions, print a single integer .
Otherwise, in the first line, print the number of used wires . In each of the following lines, print two integers and , denoting the indices of the nodes connected with the -th wire (; ).