{"trustable":true,"sections":[{"title":"","value":{"format":"MD","content":"Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an $N \\times N$ grid $(1 \\leq N \\leq 500)$. The grid contains $K$ asteroids $(1 \\leq K \\leq 10,000)$, which are conveniently located at the lattice points of the grid.\n\nFortunately, Bessie has a powerful weapon that can vaporize all the asteroids in any given row or column of the grid with a single shot.This weapon is quite expensive, so she wishes to use it sparingly.Given the location of all the asteroids in the field, find the minimum number of shots Bessie needs to fire to eliminate all of the asteroids."}},{"title":"Input","value":{"format":"MD","content":"The first line contains a single integer $t (1 \\leq t \\leq 11)$, the number of test cases.\n\nEach case begins with two integers $N$ and $K$, separated by a single space.Then $K$ lines follows,each line contains two space-separated integers $R$ and $C (1 \\leq R, C \\leq N)$ denoting the row and column coordinates of an asteroid, respectively."}},{"title":"Output","value":{"format":"MD","content":"For each case, print an integer representing the minimum number of times Bessie must shoot."}},{"title":"Sample 1","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e1\n3 4\n1 1\n1 3\n2 2\n3 2\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"MD","content":"#####INPUT DETAILS:\nThe following diagram represents the data, where `X` is an asteroid and `.` is empty space:\n```\nX.X\n.X.\n.X.\n```\n#####OUTPUT DETAILS:\nBessie may fire across row $1$ to destroy the asteroids at $(1,1)$ and $(1,3)$, and then she may fire down column $2$ to destroy the asteroids at $(2,2)$ and $(3,2)$."}}]}