What is wrong with this code?

#include
#include

using namespace std;

int comp(int a[], int b[], int n) {
int adig, bdig,anum=0,bnum=0, i=-1, j=-1;
while (i<n and j<n) {
if (anum==0) {
i++;
if (i==n) {
break;
}
anum=a[i];
}
if (bnum==0) {
j++;
if (j==n) {
break;
}
bnum=b[j];
}
adig=anum%10;
bdig=bnum%10;
if (adig>bdig) {
return 1;
}
else if(bdig>adig){
return -1;
}
anum/=10;
bnum/=10;
}
return 0;
}

int main() {
int t, n, a[100], temp[100];
int max[100]={0};
cin>>t;
for (int test=1;test<=t;test++) {
cin>>n;
for (int i=0;i<=n-1;i++) {
cin>>a[i];
temp[i]=a[i];
}

	do {
		if (comp(a, max ,n)==1){
			for (int j=0;j<=n-1;j++) {
				max[j]=a[j];
			}
		}
		for (int j=0;j<=n-1;j++) {
		cout<<a[j];
	}
	cout<<endl;
		next_permutation(a, a+n);
	} while (comp(a,temp,n)!=0);

	//for (int j=0;j<=n-1;j++) {
	//	cout<<max[j];
	//}
}
//int a[]={1,2,3};
//int b[]={1,2,3};
//cout<<comp(a,b,3);
return 0;

}

@Ayush280301
here is one sample test case.
INPUT:
1
4
0 90 32 9009

EXPECTED OUTPUT: 909009320
try to debug with this