I dont know what is wrong with my code. for 1 testcase it is giving correct ouput but not for other

My issue

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    int a[n],b[n];
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	    }
	    for(int i=0;i<n;i++)
	    {
	        cin>>b[i];
	    }
	    //sort(a,a+n);
	    int small=a[0];
	    int index=0;
	    int index1,index2;
	    
	    for(int i=1;i<n;i++)
	    {
	        if(small<a[i])
	        {
	            small=a[i];
	            index=i;
	            
	        }
	        else if(small==a[i])
	        {
	            index1=index;
	            index2=i;
	        }
	    }
	    
	    if(index==index1 && index1!=-1 && index2!=-1)
	    {
	        if(b[index1]>b[index2])
	        {
	            cout<<index1+1<<endl;
	        }
	        else
	        {
	            cout<<index2+1<<endl;
	        }
	    }
	    else
	    {
	        cout<<index+1<<endl;
	    }
	    
	    
	}
	return 0;
}

Problem Link: FACEBOOK Problem - CodeChef