Next-permutation problem doubt

#include
#include
using namespace std;
int main() {
int t;
cin>>t;
while(t–){
int n;
cin>>n;
int *arr = new int[n];
for(int i = 0 ; i <n ; i ++) {
cin>>arr[i];
}

  next_permutation(arr,arr+n);
  			for(int i = 0 ; i <n ; i ++) {
		cout<<arr[i]<<" ";
	}	
  	cout<<endl;
}

return 0;

}
when i submit this code it gave me wrong answer but i didn’t get it why

hey @keshavgupta0103 your code is working fine, on being given the input
1
5
1 2 3 4 5
it return
1 2 3 5 4
which is the next permuation.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

#include
using namespace std;
#include
int main()
{
int t,n;

cin>>t;
while(t--)
{
	int a[1000];
	
	cin>>n;
	
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	next_permutation(a,a+n);
	

for(int i=0;i<n;i++)
{
	cout<<a[i]<<"  ";
}
}	

}

why is this code not pass any test case ?