Can anyone pls tell me where I'm wrong code:SLOWSOLN

It passes on two test cases and fails on the other two can’t figure out why, I’ve seen accepted solns and they kinda approached it another way , just wanna know which condition ive missed out in mine

#include
#include<math.h>
using namespace std;

int main()
{
int t;
cin>>t;
while(t–)
{
int mt,mn,sn,sum=0,i;
cin>>mt>>mn>>sn;
for(i=1;i<mt;i++)
{
if(i*mn>=sn)
break;
}
while(i–)
{
if(sn>=mn)
{
sum=sum+pow(mn,2);
sn=sn-mn;
}
if(sn<mn)
{

        sum=sum+pow(sn,2);
        break;
        }
        if(sn==0)
        break;
    }
    
    cout<<sum<<endl;
}
// your code goes here
return 0;

}