
You are given a paper with dimension N * M. Your task is to find the minimum number of squares in which you can cut the given paper.
Note:
1. Square is a quadrilateral whose all four sides are of equal length.
2. If the given paper is already a square then it is possible to cut the whole square in one move.
The first line of the input contains an integer T, denoting the number of test cases.
The first line of each test case consists of two space-separated integers N and M denoting the dimensions of the given paper, in a separate line.
Output Format:
For each test case return, the minimum number of squares in which you can cut the given paper.
Note:
You don't have to print anything, it has already been taken care of. Just Implement the given function.
1<= T <= 50
1<= N, M <= 150
Time Limit: 1 sec.
1
2 3
3
We can cut one square with side 2 and two squares with side 1.
1
13 11
6

As given in the picture we can cut 5 squares out of paper with dimension 13*11.
Try all possible ways to cut the paper.
Eg. For paper with dimension (2, 3), the algorithm will work as follows:
O(M*N^2 + N*M^2), where N and M are the dimensions of a given paper.
As there is N*M number of different pairs of (N, M), it takes O(N*M) order of time to compute the answer for all possible (N, M) states.
Also for calculating the answer for a state (N, M) it requires extra (N + M) operations.
Hence overall it takes O(M*N^2 + N*M^2) order of operations.
O(N*M), where N and M are the dimensions of a given paper.
As we are storing answers for all pairs (N, M), hence it takes O(N*M) order of memory.