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.util.*;
  import java.awt.Paint;
  import java.io.*;
  
  public class Main {
  	static int inf=Integer.MAX_VALUE;
  	public static int[]sol(ArrayList<int[]> a){
  		int n=a.size();
  		for(int i=0;i<n;i++) {
  			boolean can=true;
  			for(int j=0;j<n;j++) {
  				if(j==i)continue;
  				int g=0;
  				for(int k=0;k<5;k++) {
  					if(a.get(i)[k]<a.get(j)[k]) {
  						g++;
  					}
  				}
  				if(g<3) {
  					can=false;
  					break;
  				}
  			}
  			if(can) {
  				return a.get(i);
  			}
  		}
  		return new int[] {inf,inf,inf,inf,inf};
  	}
  	public static void main(String[] args) throws Exception {
  
  		
  		
  		int t=sc.nextInt();
  		while(t-->0) {
  			int n=sc.nextInt();
  			int k=sc.nextInt();
  			TreeSet<Integer>a=new TreeSet<Integer>();
  			TreeSet<Integer>b=new TreeSet<Integer>();
  			ArrayList<pair>c=new ArrayList<pair>();
  			for(int i=1;i<=n*2;i++) {
  				a.add(i);
  				
  			}
  			int ans=0;
  			for(int i=0;i<k;i++) {
  				int x=sc.nextInt();
  				int y=sc.nextInt();
  				a.remove(x);
  				a.remove(y);
  				for(pair j:c) {
  					if(j.x<x&&x<j.y&&(j.x>y||j.y<y)) {
  						ans++;
  					}else if(j.x<y&&y<j.y&&(j.x>x||j.y<x)) {
  						ans++;
  					}
  				}
  				c.add(new pair(Math.min(x, y), Math.max(x, y)));
  			}
  			int N=a.size();
  			for(int i=0;i<N/2;i++) {
  				b.add(a.pollFirst());
  			}
  			while(!a.isEmpty()) {
  				int x=a.pollFirst();
  				int y=b.pollFirst();
  				a.remove(x);
  				a.remove(y);
  				for(pair j:c) {
  					if(j.x<x&&x<j.y&&(j.x>y||j.y<y)) {
  						ans++;
  					}else if(j.x<y&&y<j.y&&(j.x>x||j.y<x)) {
  						ans++;
  					}
  				}
  				c.add(new pair(Math.min(x, y), Math.max(x, y)));
  			}
  			pw.println(ans);
  			
  		}
  		
  		
  		pw.close();
  	}
  
  	static class Scanner {
  		StringTokenizer st;
  		BufferedReader br;
  
  		public Scanner(InputStream s) {
  			br = new BufferedReader(new InputStreamReader(s));
  		}
  
  		public Scanner(FileReader r) {
  			br = new BufferedReader(r);
  		}
  
  		public String next() throws IOException {
  			while (st == null || !st.hasMoreTokens())
  				st = new StringTokenizer(br.readLine());
  			return st.nextToken();
  		}
  
  		public int nextInt() throws IOException {
  			return Integer.parseInt(next());
  		}
  
  		public long nextLong() throws IOException {
  			return Long.parseLong(next());
  		}
  
  		public String nextLine() throws IOException {
  			return br.readLine();
  		}
  
  		public double nextDouble() throws IOException {
  			String x = next();
  			StringBuilder sb = new StringBuilder("0");
  			double res = 0, f = 1;
  			boolean dec = false, neg = false;
  			int start = 0;
  			if (x.charAt(0) == '-') {
  				neg = true;
  				start++;
  			}
  			for (int i = start; i < x.length(); i++)
  				if (x.charAt(i) == '.') {
  					res = Long.parseLong(sb.toString());
  					sb = new StringBuilder("0");
  					dec = true;
  				} else {
  					sb.append(x.charAt(i));
  					if (dec)
  						f *= 10;
  				}
  			res += Long.parseLong(sb.toString()) / f;
  			return res * (neg ? -1 : 1);
  		}
  
  		public long[] nextlongArray(int n) throws IOException {
  			long[] a = new long[n];
  			for (int i = 0; i < n; i++)
  				a[i] = nextLong();
  			return a;
  		}
  
  		public Long[] nextLongArray(int n) throws IOException {
  			Long[] a = new Long[n];
  			for (int i = 0; i < n; i++)
  				a[i] = nextLong();
  			return a;
  		}
  
  		public int[] nextIntArray(int n) throws IOException {
  			int[] a = new int[n];
  			for (int i = 0; i < n; i++)
  				a[i] = nextInt();
  			return a;
  		}
  
  		public Integer[] nextIntegerArray(int n) throws IOException {
  			Integer[] a = new Integer[n];
  			for (int i = 0; i < n; i++)
  				a[i] = nextInt();
  			return a;
  		}
  
  		public boolean ready() throws IOException {
  			return br.ready();
  		}
  
  	}
  
  	static class pair implements Comparable<pair> {
  		long x;
  		long y;
  
  		public pair(long x, long y) {
  			this.x = x;
  			this.y = y;
  		}
  
  		public String toString() {
  			return x + " " + y;
  		}
  
  		public boolean equals(Object o) {
  			if (o instanceof pair) {
  				pair p = (pair) o;
  				return p.x == x && p.y == y;
  			}
  			return false;
  		}
  
  		public int hashCode() {
  			return new Long(x).hashCode() * 31 + new Long(y).hashCode();
  		}
  
  		public int compareTo(pair other) {
  			if (this.x == other.x) {
  				return Long.compare(this.y, other.y);
  			}
  			return Long.compare(this.x, other.x);
  		}
  	}
  
  	static class tuble implements Comparable<tuble> {
  		int x;
  		int y;
  		int z;
  
  		public tuble(int x, int y, int z) {
  			this.x = x;
  			this.y = y;
  			this.z = z;
  		}
  
  		public String toString() {
  			return x + " " + y + " " + z;
  		}
  
  		public int compareTo(tuble other) {
  			if (this.x == other.x) {
  				if (this.y == other.y) {
  					return this.z - other.z;
  				}
  				return this.y - other.y;
  			} else {
  				return this.x - other.x;
  			}
  		}
  	}
  
  	static long mod = 1000000007;
  	static Random rn = new Random();
  	static Scanner sc = new Scanner(System.in);
  	static PrintWriter pw = new PrintWriter(System.out);
  }