What mistake i m doing and which test case i am leaving

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=max(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

@nikhil_7119
for n=8 and m=5 your code will give 10 as answer but it is not possible to divide 8*5 field in 10 prefect sq field with equal areas
so the answer for this is 40
i have coded it with correct logic that is of taking gcd of n and m;
hope u will get it
include <bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin >> t;

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

}