description: On a circle lie 2n distinct points, with the following property: however you choose 3 chords that connect 3 disjoint pairs of points, no point strictly inside the circle belongs to all 3 chords. The points are numbered 1,   2,   ...,   2n in clockwise order.
  
  Initially, k chords connect k pairs of points, in such a way that all the 2k endpoints of these chords are distinct.
  
  You want to draw n - k additional chords that connect the remaining 2(n - k) points (each point must be an endpoint of exactly one chord).
  
  In the end, let x be the total number of intersections among all n chords. Compute the maximum value that x can attain if you choose the n - k chords optimally.
  
  Note that the exact position of the 2n points is not relevant, as long as the property stated in the first paragraph holds.
  
  Input
  
  The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow.
  
  The first line of each test case contains two integers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ n) — half the number of points and the number of chords initially drawn.
  
  Then k lines follow. The i-th of them contains two integers x_i and y_i (1 ≤ x_i,   y_i ≤ 2n, x_i ≠ y_i) — the endpoints of the i-th chord. It is guaranteed that the 2k numbers x_1,   y_1,   x_2,   y_2,   ...,   x_k,   y_k are all distinct.
  
  Output
  
  For each test case, output the maximum number of intersections that can be obtained by drawing n - k additional chords.
  
  Example
  
  Input
  
  
  4
  4 2
  8 2
  1 5
  1 1
  2 1
  2 0
  10 6
  14 6
  2 20
  9 10
  13 18
  15 12
  11 7
  
  
  Output
  
  
  4
  0
  1
  14
  
  Note
  
  In the first test case, there are three ways to draw the 2 additional chords, shown below (black chords are the ones initially drawn, while red chords are the new ones):
  
  <image>
  
  We see that the third way gives the maximum number of intersections, namely 4.
  
  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 1-3 and 2-4, as shown below:
  
  <image>
solution: import java.io.*;
  import java.util.*;
  
  public class C {
      static class FastReader {
          BufferedReader br;
          StringTokenizer st;
  
          public FastReader() {
              br = new BufferedReader(new
                      InputStreamReader(System.in));
          }
  
          String next() {
              while (st == null || !st.hasMoreElements()) {
                  try {
                      st = new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
              return st.nextToken();
          }
  
          int nextInt() {
              return Integer.parseInt(next());
          }
  
          long nextLong() {
              return Long.parseLong(next());
          }
  
          double nextDouble() {
              return Double.parseDouble(next());
          }
  
          String nextLine() {
              String str = "";
              try {
                  str = br.readLine();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              return str;
          }
      }
  
      static FastReader s = new FastReader();
      static PrintWriter out = new PrintWriter(System.out);
  
      private static int[] rai(int n) {
          int[] arr = new int[n];
          for (int i = 0; i < n; i++) {
              arr[i] = s.nextInt();
          }
          return arr;
      }
  
      private static int[][] rai(int n, int m) {
          int[][] arr = new int[n][m];
          for (int i = 0; i < n; i++) {
              for (int j = 0; j < m; j++) {
                  arr[i][j] = s.nextInt();
              }
          }
          return arr;
      }
  
      private static long[] ral(int n) {
          long[] arr = new long[n];
          for (int i = 0; i < n; i++) {
              arr[i] = s.nextLong();
          }
          return arr;
      }
  
      private static long[][] ral(int n, int m) {
          long[][] arr = new long[n][m];
          for (int i = 0; i < n; i++) {
              for (int j = 0; j < m; j++) {
                  arr[i][j] = s.nextLong();
              }
          }
          return arr;
      }
  
      private static int ri() {
          return s.nextInt();
      }
  
      private static long rl() {
          return s.nextLong();
      }
  
      private static String rs() {
          return s.next();
      }
  
      static long gcd(long a,long b)
      {
          if(b==0)
          {
              return a;
          }
          return gcd(b,a%b);
      }
  
      static int gcd(int a,int b)
      {
          if(b==0)
          {
              return a;
          }
          return gcd(b,a%b);
      }
  
      static boolean isPrime(int n) {
          //check if n is a multiple of 2
          if (n % 2 == 0) return false;
          //if not, then just check the odds
          for (int i = 3; i <= Math.sqrt(n); i += 2) {
              if (n % i == 0)
                  return false;
          }
          return true;
      }
      static int MOD=1000000007;
  
      static long mpow(long base,long pow)
      {
          long res=1;
          while(pow>0)
          {
              if(pow%2==1)
              {
                  res=(res*base)%MOD;
              }
              pow>>=1;
              base=(base*base)%MOD;
          }
          return res;
      }
  
      static TreeSet<Long> set= new TreeSet<>();
      static void sieveOfEratosthenes(int n)
      {
          // Create a boolean array
          // "prime[0..n]" and
          // initialize all entries
          // it as true. A value in
          // prime[i] will finally be
          // false if i is Not a
          // prime, else true.
          boolean[] prime = new boolean[n + 1];
          for (int i = 0; i <= n; i++)
              prime[i] = true;
  
          for (int p = 2; p * p <= n; p++)
          {
              // If prime[p] is not changed, then it is a
              // prime
              if (prime[p])
              {
                  // Update all multiples of p
                  for (int i = p * p; i <= n; i += p)
                      prime[i] = false;
              }
          }
  
          // Print all prime numbers
          for (int i = 2; i <= n; i++)
          {
              if (prime[i])
              {
                  for(int pow = 1;pow<=10;pow++) {
                      long val = (long) Math.pow((long)i, pow);
                      set.add(val);
                      if(val>1000)
                      {
                          break;
                      }
                  }
              }
          }
      }
  
      static long smallestDivisor(long n)
      {
          // if divisible by 2
          if (n % 2 == 0)
              return 2;
  
          // iterate from 3 to sqrt(n)
          for (long i = 3; i * i <= n; i += 2) {
              if (n % i == 0)
                  return i;
          }
  
          return n;
      }
      static class Pair
      {
          int i,j;
  
          public Pair(int i, int j) {
              this.i = i;
              this.j = j;
          }
  
          @Override
          public String toString() {
              return "("+i+","+j+")";
          }
      }
      public static void main(String[] args) {
          StringBuilder ans = new StringBuilder();
          int t = ri();
  //        int t = 1;
          while (t-- > 0)
          {
              int n=ri();
              int k=ri();
              List<Pair> list= new ArrayList<>();
              TreeSet<Integer> set = new TreeSet<>();
              for(int i=1;i<=2*n;i++)
              {
                  set.add(i);
              }
              for(int i=0;i<k;i++)
              {
                  int a = ri();
                  int b = ri();
                  set.remove(a);
                  set.remove(b);
                  list.add(new Pair(Math.min(a,b), Math.max(a,b)));
              }
  
  
              List<Integer> rem = new ArrayList<>(set);
  
              for(int i=0;i<rem.size()/2;i++)
              {
                  int ind = i+(rem.size()/2);
                  list.add(new Pair(rem.get(i), rem.get(ind)));
              }
  
              list.sort(Comparator.comparingInt(o -> o.i));
  //            System.out.println(list);
              int count = 0;
              for(int i=1;i<list.size();i++)
              {
                  for(int j=0;j<i;j++)
                  {
                      Pair p2 = list.get(i);
                      Pair p1 = list.get(j);
  
                      if(p2.i>p1.j)
                      {
                          continue;
                      }
                      if(p2.i<p1.i && p2.j>p1.j)
                      {
                          continue;
                      }
                      if(p2.i>p1.i && p2.j<p1.j)
                      {
                          continue;
                      }
  //                    System.out.println(p1+" "+p2);
                      count++;
                  }
              }
  
              ans.append(count).append("\n");
          }
          out.print(ans.toString());
          out.flush();
      }
  
  }