#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
void MOUST(){
ios_base::sync_with_stdio(0);
cin.tie(0);
}
ll p(ll a,ll b){
return a*b+a-b;
}
int main(){
MOUST();
int q;cin>>q;
while(q--){
ll n,k=0,p=0;cin>>n;
ll a[n];
for(int i=0;i<n;i++){
cin>>a[i];
k=max(k,a[i]);
}
for(int i=0;i<n;i++)
if(a[i]==k)
p++;
if(p>2)
cout<<"-1\n";
else
cout<<n-p+1<<"\n";
}
}