// Arup Guha
// 5/7/2019
// Solution to 2019 FHSPS Playoff Problem: Queen Coverage

import java.util.*;

public class queen {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();
		
		// Process each case.
		for (int loop=0; loop<numCases; loop++) {
			
			// Get basic parameters.
			int n = stdin.nextInt();
			int numq = stdin.nextInt();
			
			// Stores whether each of these items is covered or not.
			boolean[] rows = new boolean[n];
			boolean[] cols = new boolean[n];
			boolean[] fDiag = new boolean[2*n-1];
			boolean[] bDiag = new boolean[2*n-1];
			
			// Just go through each queen marking which row, column, forward diagonal and backward diagonal it belongs to.
			for (int i=0; i<numq; i++) {
				
				// Get 0 based location of queen.
				int r = stdin.nextInt()-1;
				int c = stdin.nextInt()-1;
				
				// Mark it's four items as being covered.
				rows[r] = true;
				cols[c] = true;
				fDiag[r+c] = true;
				bDiag[r-c+n-1] = true;
			}
			
			// Now, just go through each square and see if it's covered or not.
			int res = 0;
			for (int i=0; i<n; i++) 
				for (int j=0; j<n; j++) 
					if (rows[i] || cols[j] || fDiag[i+j] || bDiag[i-j+n-1])
						res++;
				
			// Ta da!
			System.out.println(res);
		}
	}
}