I have updated the code to this:
#include<iostream>
#include<vector>
#include<string>
typedef unsigned long long int ll;
using namespace std;
main()
{
ll T, N;
int a;
vector<string> ans;
cin>>T;
while(T--)
{
vector<int> A;
string y;
cin>>N;
for(ll i=0; i<N; i++)
{
cin>>a;
y += to_string(a);
A.push_back(a);
}
int temp, pos=N-1, minVal = A[N-1], min_i = N-1;
for(ll i=N-1; i>0; i--)
{
if(A[i]>A[i-1])
{
if(A[min_i]<A[i-1])
{
for(int k=i; k<N-1; k++)
if(A[k]>A[i-1])
min_i = k;
}
temp = A[i-1];
A[i-1] = A[min_i];
A[min_i] = temp;
int arr[N-i];
for(int k = N-1; k>i-1; k--)
arr[N-1-k] = A[k];
for(int k=0; k<N-i; k++)
A[k+i] = arr[k];
break;
}
else if(A[min_i]>A[i])
{
min_i = i;
}
}
string x = to_string(A[0]);
for(int i=1; i<N; i++)
x += to_string(A[i]);
if(x==y)
x = "-1";
ans.push_back(x);
}
for(int i=0; i<ans.size(); i++)
cout<<ans[i]<<endl;
}
But then, it still shows WA. What could be the reason?