#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<map>
#include<stack>
#include<queue>
#include<math.h>

using namespace std;

#define int long long
#define mod 1000000007


int ans = 0;

vector<int>graph[200001];
vector<int>visited(200001, -1);




void dfs(vector<int>graph[], int start, vector<int>&visited)
{
    visited[start] = 1;

    for (auto i : graph[start])
    {
        if (visited[i] == -1)
        {   ans++;
            dfs(graph, i, visited);
        }
    }

}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif


    int n;
    cin >> n;

    vector<int>arr(n);
    for (int i = 0; i < n; i++)
        cin >> arr[i];

    int i = 0;
    int j = n - 1;
    while (i < j)
    {

        graph[arr[i]].push_back(arr[j]);
        graph[arr[j]].push_back(arr[i]);

        i++;
        j--;
    }


    for (int i = 0; i < arr.size(); i++)
    {
        if (visited[arr[i]] == -1)
        {

            dfs(graph, arr[i], visited);
        }
    }
    cout << ans << endl;
}
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
using namespace std;
#define int long long
#define endl "\n"
#define deb(x) cout<<#x<<" "<<x<<endl;
#define sc(ar,n) for(int pen=0;pen<n;pen++){ cin>>ar[pen];}
#define pr(ar,n) for(int pen=0;pen<n;pen++){ cout<<ar[pen]<<" ";} cout<<endl;
#define fr(i,x,n) for(int i=x;i<n;i++)
#define frt(it,vb) for(auto it=vb.begin();it!=vb.end();it++)
#define mem(ar,x) memset(ar,x,sizeof(ar));
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define rt return 0;
#define ct continue;
#define MAX 1000000000000000000
#define MAX1 1000000000
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

inline int solve()
{
    int n;
    cin>>n;
    int ar[n];
    sc(ar,n);
    vector <int> vt[200010];
    fr(i,0,n/2){
        if(ar[i] != ar[n-i-1]){
            vt[ar[i]].push_back(ar[n-i-1]);
            vt[ar[n-i-1]].push_back(ar[i]);
        }
    }
    int vis[200010];
    mem(vis,0);
    int ans = 0;
    fr(i,1,200010){
        if(vis[i] == 0){
            queue <int> q;
            q.push(i);
            vis[i] = 1;
            int c = 0;
            while(!q.empty()){
                int x = q.front();
                q.pop();
                c++;
                frt(it,vt[x]){
                    if(vis[*it] == 0){
                        q.push(*it);
                        vis[*it] = 1;
                    }
                }
            }
            ans += c-1;
        }
    }
    cout << ans << endl;
    rt;
}
signed main()
{
    // fastio;
    int t;
    int test_cases=1;
    if(test_cases==0)
    cin>>t;
    else
    t=1;
    while(t--){
        solve();
    }
}