#include<iostream>
#include<vector>
#include <map>
using namespace std;
int n = 1000001;
int main(){
int Test;
cin>>Test;
while(Test>0){
int numberOfStudents;
cin>>numberOfStudents;
int max=-1;
map <int,int> ans;
for(int i=0;i<numberOfStudents;i++){
int loki;
cin>>loki;
if(max < loki){
max = loki;
}
ans[loki]+=1;
}
if (ans[max]==1){
cout<<numberOfStudents<<endl;
} else if(ans[max]==2){
cout<<numberOfStudents-1<<endl;
}
else{
cout<<-1<<endl;
}
Test--;
}
}