

The first line contains a single integer ‘T’ denoting the number of test cases. The test cases are as follows.
The first line of each test case contains three integers ‘X’, ‘N’ and ‘M’ separated by a single space denoting the element to be searched, the number of rows in the matrix, and the number of columns in the matrix respectively.
The next ‘N’ lines contain ‘M’ integers each denoting the elements of the matrix.
For each test case, print “Yes”(without quotes) if ‘X’ is present in the matrix otherwise print “No”.
Print the output of each test case on a new line.
You don’t need to print anything; It has already been taken care of.
1 <= T <= 50
1 <= X <= 10 ^ 6
1 <= N, M <= 100
-10 ^ 6 <= ARR[i][j] <= 10 ^ 6
Where ‘T’ denotes the number of test cases, ‘N’ denotes the number of rows in a matrix, ‘M’ denotes the number of columns in the matrix and ARR[i][j] denotes the j-th element of the i’th row of the given matrix.
Time Limit: 1 sec
The idea is to iterate through the matrix and check if any element is equal to ‘X’.
The steps are as follows :
The idea is to use the property of sorted rows of the matrix and apply binary search on each row.
The steps are as follows :
The idea is to use the fact that each row is sorted and the first element of each row is greater than the last element of the previous row. We will try to visualize the 2D matrix as a 1D array. The j’th element of the i’th row i.e. arr[i][j] can be represented by giving it an index value of i*M + j. This way each element will have a unique index value and we can apply binary search on the complete matrix.
The steps are as follows :