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< stdio.h >
    #include< iostream >
    #include< sstream >
    #include< string.h>
    #include< algorithm>
    #include< stdlib.h>
    #define maxn 105
    using namespace std;
    int dp[maxn][maxn],n,m;
    void precalc()	
    {
        memset(dp,1,sz(dp));
        for(int i = 0; i <=100;i++)
            dp[i][0] = 0;
        for(int i=0; i<=100;i++)
            dp[0][i] = 0;
        for(int i=1;i<=100;i++)
        {
            for(int j=1;j<=100;j++)
            {
                if(i == j) {
                    dp[i][j] = 1;
                }else
                {
                    for(int k = 1;k<j;k++)
                        dp[i][j] = min(dp[i][k] + dp[i][j-k],dp[i][j]);
                    for(int k = 1;k<i;k++)
                        dp[i][j] = min(dp[k][j] + dp[i-k][j],dp[i][j]);
                }
                dp[j][i] = dp[i][j];
            }
        }
    }
    int main() {
        int tt;
        precalc();
        cin>>tt;
        while(tt--)
        {
            cin>>n>>m;
            cout<<dp[n][m]<<endl;
        }
        return 0;
    }