

‘M’ is ‘3’, ‘N’ is ‘4’and ‘K’ is ‘5’. For this input, multiplication table is:

So the ‘5th’ smallest number is ‘3’(‘1’, ‘2’, ‘3’, ‘3’, ‘4’, ‘4’, ‘6’, ‘6’, ‘8’, ‘9’, ‘12’)
The first line of input contains a ‘T’ number of test cases.
In the second line, three space-separated integers ‘M’, ‘N', and ‘K' denoting height and length of the multiplication table, and ‘K’ represents the ‘Kth’ smallest number which we have to find from the multiplication table.
For each test case, print a single line containing a single integer denoting the ‘Kth’ smallest number.
The output of each test case will be printed in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10000
1 <= M,N <= 10 ^ 7
1<= K <= M*N
Time Limit: 1 second.
As we know the matrix is sorted so we can think of a binary search to find the kth smallest element. To optimize our Brute force approach we now use the concept of binary search.
Here is the algorithm: