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.*;
  import java.math.BigDecimal;
  
  public class Main{
  	public static void main(String[] args) {
  	      TaskA solver = new TaskA();
  	      int t = in.nextInt();
  	      for (int i = 1; i <= t ; i++) {
  	          solver.solve(1, in, out);
  	      }
  	      out.flush();
  	    out.close();
  	  }
  		
  	 static class TaskA {
  	      public void solve(int testNumber, InputReader in, PrintWriter out) {
  	    	  	 int n=in.nextInt(),k=in.nextInt();
  	    	  	 ArrayList<Integer>a=al(),b=al();
  	    	  	 boolean[]bo=new boolean[2*n];
  	    	  	 for(int i=0;i<k;i++) {
  	    	  		 a.add(in.nextInt()-1);b.add(in.nextInt()-1);
  	    	  		 bo[a.get(i)]=true;bo[b.get(i)]=true;
  	    	  	 }
  	    	  	 ArrayList<Integer>r=al();
  	    	  	 for(int i=0;i<2*n;i++) {
  	    	  		 if(!bo[i]) {
  	    	  			 r.add(i);
  	    	  		 }
  	    	  	 }
  	    	  	int cnt = (int) r.size();
  	    	    for (int i = 0; i < cnt / 2; i++) {
  	    	      a.add(r.get(i));
  	    	      b.add(r.get(i + cnt / 2));
  	    	    }
  	    	    assert((int) a.size() == n);
  //	    	    debug(a);
  //	    	    debug(b);
  	    	    for(int i=0;i<n;i++) {
  	    	    	if (a.get(i) > b.get(i)) {
  	    	            int temp=a.get(i);
  	    	            a.set(i, b.get(i));
  	    	            b.set(i,temp);
  	    	          }
  	    	    }
  //	    	    debug(a);
  //	    	    debug(b);
  	    	    int ans=0;
  	    	    for(int i=0;i<n;i++) {
  	    	    	for(int j=0;j<n;j++) {
  	    	    		if(a.get(i)<a.get(j)&&b.get(i)>a.get(j)&&b.get(j)>b.get(i)) {
  	    	    			ans++;
  	    	    		}
  	    	    	}
  	    	    }
  	    	    out.println(ans);
  	      }
  	  }
  	 
  	 static int nD(int n) {
  		 int count =0;
  		 while(n>0) {
  			 n/=10;
  			 count++;
  			 
  		 }
  		 return count;
  	 }
  	 static ArrayList al() {
  		 ArrayList<Integer>a =new ArrayList<>();
  			return a;
  		}
  	static HashSet h() {
  			return new HashSet<Integer>();
  		}
  	static void debug(int[]a) {
  			out.println(Arrays.toString(a));
  		}
  	static void debug(ArrayList<Integer>a) {
  				out.println(a.toString());
  		}
  	 static int longestIncreasingSubseq(int[]arr) {
  		  int[]sizes=new int[arr.length];
  		  Arrays.fill(sizes, 1);
  		  int max=1;
  		  for(int i=1;i<arr.length;i++) {
  			  for(int j=0;j<i;j++) {
  				  if(arr[j]<arr[i]) {
  					  sizes[i]=Math.max(sizes[i],sizes[j]+1);
  					  max=Math.max(max, sizes[i]);
  				  }
  			  }
  		  }
  		  return max;
  	 }
  	 static boolean Divisors(long n){
  		 if(n%2==1) {
  			 return true;
  		 }
  	     for (long i=2; i<=Math.sqrt(n); i++){
  	            if (n%i==0 && i%2==1){
  	                   return true;
  	            } 
  	        }
  	     return false;
  	    }
  	
  	private static class Direction{
  		int left;
  		int right;
  		int up;
  		int down;
  		int value;
  		public Direction(int value){
  			this.value=value;
  		}
  	}
  	static InputStream inputStream = System.in;
      static OutputStream outputStream = System.out;
      static InputReader in = new InputReader(inputStream);
      static PrintWriter out = new PrintWriter(outputStream);
      
      public static void superSet(int[]a,ArrayList<String>al,int i,String s) {
      	if(i==a.length) {
      		al.add(s);
      		return;
      	}
      	superSet(a,al,i+1,s);
      	superSet(a,al,i+1,s+a[i]+" ");
      }
      
  	public static long[] makeArr() {
  		long size=in.nextInt();
  		long []arr=new long[(int)size];
  		for(int i=0;i<size;i++) {
  			arr[i]=in.nextInt();
  		}
  		return arr;
  	}
  	
  	public static long[] arr(int n) {
  		long []arr=new long[n];
  		for(int i=0;i<n;i++) {
  			arr[i]=in.nextInt();
  		}
  		return arr;
  	}
    
    public static void sort(long arr[], int l, int r)
    {
        if (l < r)
        {
            // Find the middle point
            int m = (l+r)/2;
  
            // Sort first and second halves
            sort(arr, l, m);
            sort(arr , m+1, r);
  
            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }
  
  
  public static void merge(long arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;
  
        /* Create temp arrays */
        long L[] = new long[n1];
        long R[] = new long[n2];
  
        //Copy data to temp arrays
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];
  
  
        /* Merge the temp arrays */
  
        // Initial indexes of first and second subarrays
        int i = 0, j = 0;
  
        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }
  
        /* Copy remaining elements of L[] if any */
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }
  
        /* Copy remaining elements of R[] if any */
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }
  
  public static void reverse(long[] array)
  {
      int n = array.length;
      for (int i = 0; i < n / 2; i++) {
          long temp = array[i];
          array[i] = array[n - i - 1];
          array[n - i - 1] = temp;
      }
  }
  
    public static long nCr(int n,int k)
    {
        long ans=1L;
        k=k>n-k?n-k:k;
       
        for( int j=1;j<=k;j++,n--)
        {
            if(n%j==0)
            {
                ans*=n/j;
            }else
            if(ans%j==0)
            {
                ans=ans/j*n;
            }else
            {
                ans=(ans*n)/j;
            }
        }
        return ans;
    }
    static int searchMax(int index,long[]inp) {
  	  while(index+1<inp.length &&inp[index+1]>inp[index]) {
  		  index+=1;
  	  }
  	  return index;
    }
    static int searchMin(int index,long[]inp) {
  	  while(index+1<inp.length &&inp[index+1]<inp[index]) {
  		  index+=1;
  	  }
  	  return index;
    }
  
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
  
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
  
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
  
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
      	  return Long.parseLong(next());
        }
    }
  }
  