Help me in solving BMCC18 problem

My issue

My code

// Update the code below to solve the problem

#include <bits/stdc++.h>
using namespace std;

int main() 
{
	int t;
    cin >> t;
	
	while(t--)
	{
	    int N, M,i;
	    cin >> N >> M;
	    for( i=min(N,M);i>=1;i--)
	    {
	        if(N*M%(i*i)==0)
	        break;
	    }
	    cout<<(N*M)/(i*i)<<endl;
	}
}

Learning course: Solve Programming problems using C++
Problem Link: CodeChef: Practical coding for everyone

Use this inside for loop
if(N%i==0 && M%i==0)
break;

first of all thank you for answering. Can u please tell me what was wrong in my code or which test code i left considering. by knowing ones mistakes one can learn coding in a better way with deep knowledge. So u r kindly requested to reply me with this.