
The first line of the input contains ‘T,’ denoting the number of test cases.
The first line of each test case contains two space-separated integers, ‘N’ and ‘K,’ denoting dimensions of the grid and number of queries.
The following ‘K’ lines contain two space-separated integers, 'X[i]' and 'Y[i]', denoting the coordinates of the grid.
For each test case, return the answer of each query.
Print the answer in a separate line for each query.
1 <= T <= 3
1 <= N <= 5000
1 <= K <= min(3000,N * N)
1 <= X[i], Y[i] <= N
Time limit: 1 sec
Explanation:
The steps are as follows:
Initialize a set ‘ST’ which will be used to store coordinates of the colored cells.
In each query, we have coordinates ('X[i]', ‘Y[i]’) and we do the following each time:
A cell number of a coordinate is the position this coordinate would be if we were to flatten the matrix i.e. if there was only 1 row and ‘N’ * ‘N’ column. A cell number of coordinate ('i', ‘j’) is = ‘N’ * ‘i’ + ‘j’ .