// Arup Guha
// 5/7/2019
// Alternate solution to 2019 FHSPS Playoff Problem: Queen Coverage

import java.util.*;

public class queen_alt {

	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[][] board = new boolean[n][n];
			
			// 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;
				
				for (int j=0; j<n; j++) {
					board[r][j] = true;
					board[j][c] = true;
				}
				
				// Do backward diagonal.
				int sum = r+c;
				for (int j=0; j<=sum; j++) {
					if (j >= n || sum-j >= n) continue;
					board[j][sum-j] = true;
				}
				
				// And forward diagonal.
				int min = Math.min(r,c);
				int max = Math.max(r,c);
				for (int j=-min; j<n-max; j++) 
					board[r+j][c+j] = 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 (board[i][j])
						res++;
				
			// Ta da!
			System.out.println(res);
		}
	}
}