To help those contestants who struggle a lot in contests, the headquarters of Codeforces are planning to introduce Division 5. In this new division, the tags of all problems will be announced prior to the round to help the contestants.

The contest consists of n problems, where the tag of the i-th problem is denoted by an integer a_i.

You want to AK (solve all problems). To do that, you must solve the problems in some order. To make the contest funnier, you created extra limitations on yourself. You do not want to solve two problems consecutively with the same tag since it is boring. Also, you are afraid of big jumps in difficulties while solving them, so you want to minimize the number of times that you solve two problems consecutively that are not adjacent in the contest order.

Formally, your solve order can be described by a permutation p of length n. The cost of a permutation is defined as the number of indices i (1≤ i<n) where |p_{i+1}-p_i|>1. You have the requirement that a_{p_i}≠ a_{p_{i+1}} for all 1≤ i< n.

You want to know the minimum possible cost of permutation that satisfies the requirement. If no permutations meet this requirement, you should report about it.

Input

The first line contains a single integer t (1≤ t≤ 10^4) — the number of test cases.

The first line of the description of each test case contains a single integer n (1 ≤ n ≤ 10^5) — the number of problems in the contest.

The next line contains n integers a_1,a_2,… a_n (1 ≤ a_i ≤ n) — the tags of the problems.

It is guaranteed that the sum of n over all test cases does not exceed 10^5.

Output

For each test case, if there are no permutations that satisfy the required condition, print -1. Otherwise, print the minimum possible cost of a permutation that satisfies the required condition.

Example

Input


4
6
2 1 2 3 1 1
5
1 1 1 2 2
8
7 7 2 7 7 1 8 7
10
1 2 3 4 1 1 2 3 4 1


Output


1
3
-1
2

Note

In the first test case, let p=[5, 4, 3, 2, 1, 6]. The cost is 1 because we jump from p_5=1 to p_6=6, and |6-1|>1. This permutation is valid because we don't solve problems with the same tag twice in a row. We cannot find a permutation with a cost smaller than 1.

In the second test case, let p=[1,5,2,4,3]. The cost is 3 because |p_2-p_1|>1, |p_3-p_2|>1, and |p_4-p_3|>1. The permutation is valid because we don't solve problems with the same tag twice in a row. We cannot find a permutation with a cost smaller than 3.

In the third test case, for any order of solving the problems, we will solve two problems with the same tag consecutively, so the answer is -1.
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        
        vvi st(n); vi a(n);
        for(int x = 0; x < n; x++){
            int i; cin >> i;
            st[i-1].push_back(x);
            a[x] = i-1;
        }

        bool pos = true;
        int groups = 0; vi cnt(n);
        for(int x = 0; x < n; x++){
            if(st[x].size() > (n+1)/2) pos = false;

            for(int i = 0; i < int(st[x].size())-1; i++){
                if(st[x][i]+1 == st[x][i+1])
                    groups++, cnt[x]+=2;
            }
        }
        cnt[a[0]]++; cnt[a[n-1]]++;

        if(!pos) cout << -1 << endl;
        else cout << groups+max(0, *max_element(all(cnt))-(groups+2)) << endl;

    }    

    return 0;
}
