#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void solve() {
int n;
cin >> n;
vector<int> v(n);
map<int, int> mp;
for (auto &x : v) {
cin >> x;
mp[x]++;
}
int mx = *max_element(v.begin(), v.end());
if (mp[mx] > 2) {
cout << -1 << '\n';
return;
}
cout << n - mp[mx] + 1 << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
}