

In lexicographical order, cell (a, b) comes before cell (c, d), if either a < c or (a = c and b < d).
The first line of input contains an integer ‘T’ denoting the number of test cases. The description of ‘T’ test cases follows.
The first line of each test case contains two space-separated integers ‘n’ and ‘m’ representing dimensions of the chessboard and the number of rooks that are already present in the chessboard respectively.
Then ‘m’ line follows, each containing 2 space-separated integers ‘r’, ‘c’ representing that there is a rook at cell (r, c).
For each test case, print in one line an integer ‘k’ representing the maximum number of additional rooks that can be placed on the chessboard and then print ‘k’ lines each of which contains 2 space-separated integers ‘r’ and ‘c’ representing that a rook is placed at cell (r, c). You need to print these cells in lexicographical order.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 50
1 <= n <= 10^4
0 <= m <= n
0 <= r, c < n
Where ‘T’ is the number of test cases and ‘n’ is the dimensions of the chessboard, ‘m’ is the number of rooks that are already present on the chessboard, and (r, c) represents the cell of the chessboard.
Time Limit: 1 sec
We can observe that if a rook is placed at cell (r, c), then no other rook can be placed in any cell of row ‘r’ and column ‘c’, This approach is based on the idea that a maximum of (n – m) rooks can be placed on the chessboard according to the Pigeonhole Principle. Below are the steps:
Sorted Doubly Linked List to Balanced BST
Largest Plus Sign
Minimum Operations to Form Letter Y
Matrix Block Sum
Minimized Maximum of Products Distributed to Any Store