#include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int N; cin >> N; vector A(N); for(auto &a : A) cin >> a; auto check = [&](long long x) -> bool { for(int i=0; i>= 1; if(A.at(i) == now) continue; return false; } return true; }; if(check(0)){cout << "0\n"; continue;} if(N == 1 || (N == 2 && A.at(1)-A.at(0) == -1)){cout << (1LL< dec; int even = -1; { bool ok = true; for(int i=1; i= 0) continue; ok = false; break; } if(ok) even = 0; } { bool ok = true; for(int i=2; i= 0) continue; ok = false; break; } if(ok) even = 1; } if(even == -1){cout << "-1\n"; continue;} if(even == 0){ int maxd = -1; for(int i=2; i