#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define ll long long
int main() {
IOS
int t;cin>>t;
while(t--){
int n;cin>>n;
vector<int>v(n);
for(int i = 0;i<n;i++)
cin>>v[i];
sort(v.rbegin(),v.rend());
int ans=-1;
int i=0;
while(i+1<n&&v[i]==v[i+1])
i++;
if(i==1)
ans=n-1;
else if(i>=2)
ans=-1;
else ans=n;
cout<<ans<<"\n";
}
};