Problem: On a circle lie distinct points, with the following property: however you choose chords that connect disjoint pairs of points, no point strictly inside the circle belongs to all chords. The points are numbered in clockwise order.
Initially, chords connect pairs of points, in such a way that all the endpoints of these chords are distinct.
You want to draw additional chords that connect the remaining points (each point must be an endpoint of exactly one chord).
In the end, let be the total number of intersections among all chords. Compute the maximum value that can attain if you choose the chords optimally.
Note that the exact position of the points is not relevant, as long as the property stated in the first paragraph holds.
Input Format: The first line contains a single integer () — the number of test cases. Then test cases follow.
The first line of each test case contains two integers and (, ) — half the number of points and the number of chords initially drawn.
Then lines follow. The -th of them contains two integers and (, ) — the endpoints of the -th chord. It is guaranteed that the numbers are all distinct.
Output Format: For each test case, output the maximum number of intersections that can be obtained by drawing additional chords.
Note: In the first test case, there are three ways to draw the additional chords, shown below (black chords are the ones initially drawn, while red chords are the new ones):
We see that the third way gives the maximum number of intersections, namely .
In the second test case, there are no more chords to draw. Of course, with only one chord present there are no intersections.
In the third test case, we can make at most one intersection by drawing chords and , as shown below: