// Arup Guha
// 8/31/2016
// Solution to 2016 UCF Locals Problem: Don't Break the Ice

import java.util.*;

public class breakice {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Go through each case.
		for (int loop=1; loop<=numCases; loop++) {

			int n = stdin.nextInt();
			int numMoves = stdin.nextInt();

			// Initial game board has all pieces in it.
			boolean[][] grid = new boolean[n][n];
			for (int i=0; i<n; i++)
				Arrays.fill(grid[i], true);

			// In parallel, we maintain the number of blocks on each row and column.
			int[] rowCount = new int[n];
			Arrays.fill(rowCount, n);
			int[] colCount = new int[n];
			Arrays.fill(colCount, n);

			int res = 0;

			// Go through each move.
			for (int i=0; i<numMoves; i++) {

				// Get the move.
				int r = stdin.nextInt()-1;
				int c = stdin.nextInt()-1;

				// Oops, no block here, count as invalid.
				if (!grid[r][c]) {
					res++;
					continue;
				}

				// Call recursive function that breaks this block!
				breakIt(grid, rowCount, colCount, r, c);

			}

			// Output the result.
			System.out.println("Strategy #"+loop+": "+res+"\n");
		}
	}

	// Recursively breaks the square at (r,c) which is guaranteed to exist.
	public static void breakIt(boolean[][] grid, int[] rowCount, int[] colCount, int r, int c) {

		int n = grid.length;

		// Break just this one.
		grid[r][c] = false;
		rowCount[r]--;
		colCount[c]--;

		// Only new blocks that could fall must be on row r or column c, just check
		// all of these and recursively call the function if the block is there, but needs to go.
		for (int i=0; i<n; i++) {
			if (grid[r][i] && colCount[i] < n)
				breakIt(grid, rowCount, colCount, r, i);
			if (grid[i][c] && rowCount[i] < n)
				breakIt(grid, rowCount, colCount, i, c);
		}
	}
}