Cutting paper
Difficulty: Hard

**Please note that this is a team event, and your submission will be accepted only as a part of a team, even single member teams are allowed. Please click [here](https://www.hackerrank.com/auth/create_team/csindia) to register as a team, if you have NOT already registered.**

Yami is taking a Physics class in her school. She doesn't like Physics and gets bored very fast. As a hyperactive girl, she wants to use this time in a productive manner. So she takes a rectangular sheet of paper and a pair of scissors and decides to cut the paper. While cutting the paper, the following rules are followed 

+ Paper is cut along a line that is parallel to one of the sides of the paper. 
+ Paper is cut such that the resultant dimensions are always integers.  

The process stops when all the pieces are squares. What is the *minimum* number of paper pieces cut by Yami such that all are squares?

**Input Format**  
The first line of the input is number T, the number of test cases.  
Each test case contains two space separated integers N and M, the dimensions of the sheet.

**Constraints**  
1<=T<=100  
1<=N,M<=100

**Output Format**  
For each testcase, print in a newline the minimum number of squares that can be cut by Yami.  

**Sample Input**  

    2
    1 1
    1 2

**Sample Output**

    1
    2

**Explanation**  

+ For the first testcase, the minimum number of squares that can be cut is just 1 ( the original paper )
+ For the second testcase, the minimum number of squares that can be cut is 2 ( the paper is cut horizontally along the smaller side in the middle ).  


Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (C++):
    #include<bits/stdc++.h>

    using namespace std;

    int mat[101][101];

    void solve()
    {
        mat[0][0] = 0;
        mat[0][1] = 0;
        mat[1][0] = 0;

        for(int i = 1; i <= 100; i++)
        {
            mat[i][1] = i;
            mat[1][i] = i;
        }
        for(int i = 2; i <= 100; i++)
        {
            for(int j = 2; j <= 100; j++)
            {
                int min = i * j, val;
                if(i == j)
                {
                    min = 1;
                }
                else
                {
                    for(int k = 1; k < i; k++)
                    {
                        val = mat[k][j] + mat[i - k][j];
                        if(val < min)
                            min = val;
                    }
                    for(int k = 1; k < j; k++)
                    {
                        val = mat[i][k] + mat[i][j - k];
                        if(val < min)
                            min = val;
                    }
                }
                mat[i][j] = min;
            }
        }
    }

    int main()
    {
        int n, x, y;
        cin >> n;
        solve();
        for(int i = 0; i < n; i++)
        {
            cin >> x >> y;
            cout << mat[x][y] << endl;
        }
        return 0;
    }