Under construction

Still being built. Things may change

Bipartite Graph

Time limit2sMemory limit1024 MB

Summary
Build a bipartite graph with d and d-2 vertices and at most 3d edges so that removing any two vertices from the first part still leaves a perfect matching.
Level

Medium6 of 10

Topics
Graph, Implementation, Math
Solved
No attempts yet

Problem

In this problem, you have to construct a bipartite graph with the following properties:

  1. The number of vertices in the first part is dd.
  2. The number of vertices in the second part is d−2d - 2.
  3. The number of edges is at most 3d3d.
  4. For every bipartite graph obtained by removing two vertices from the first part, there is a perfect matching.

A bipartite graph has its vertices divided into two parts so that each edge connects a vertex from the first part with a vertex from the second part. A perfect matching is a set of edges such that every vertex of the graph is an endpoint of exactly one edge in the set.

Input

The first line contains an integer TT, the number of test cases (1≤T≤1001 \le T \le 100). Each of the next TT lines contains an integer dd, the number of vertices in the corresponding test case (3≤d≤1003 \le d \le 100).

Output

For each test case, print an integer mm, the number of edges, on its own line. Then print mm lines, each describing one edge as a pair of integers uu and vv: the numbers of the vertices in the first and second part connected by that edge (0≤u<d0 \le u < d, 0≤v<d−20 \le v < d - 2).

The graph must not contain multiple edges.

Hint

You do not need to minimize the number of edges.

Examples1

  1. Example 1

    Input
    1
    4
    
    Expected output
    7
    0 1
    1 0
    1 1
    2 0
    2 1
    3 0
    3 1