Anyone can tell me what's wrong in this code of Q= Problem Code: SLOWSOLN

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;cin>>t;
	while(t--){
	    int a,b,c,d,e;cin>>a>>b>>c;//a=maxT,b=maxN,c=sumN
	    d=c/b;
	    if(a>d && c%b==0){
	        a=d;
	        cout<<d*(b*b)<<endl;
	    }else {
	        if(d>a && c%b==0){
	            a=a;
	            cout<<a*(b*b)<<endl;
	        }else { if(a>d && c%b!=0){
	            a=(c/b)+1;
	            e=c%b;
	            cout<<(d*(b*b))+(e*e)<<endl;
	        }else{ 
	             a=(c/b)+1;
	            e=c%b;
	            cout<<(d*(b*b))+(e*e)<<endl;
	        }
	    }
	}
	}
	return 0;
}