#include<bits/stdc++.h> #define re register #define ll long long
usingnamespace std;
constint N = 3e5 + 10; int T,n,p,idx; ll ans; int arr[N];
structnode{ ll val; int u,fa; unordered_map<int,int> son; }tr[N];
inlineintread(){ int r = 0,w = 1; char c = getchar(); while (c < '0' || c > '9'){ if (c == '-') w = -1; c = getchar(); } while (c >= '0' && c <= '9'){ r = (r << 3) + (r << 1) + (c ^ 48); c = getchar(); } return r * w; }
inlinevoidsolve(){ ans = 0; p = idx = 1; n = read(); for (re int i = 1;i <= n;i++){ tr[i].val = tr[i].u = tr[i].fa = 0; tr[i].son.clear(); arr[i] = read(); } for (re int i = 1;i <= n;i++){ if (arr[i] == tr[p].u) p = tr[p].fa; else{ int v; if (!tr[p].son.count(arr[i])){ tr[p].son[arr[i]] = v = ++idx; tr[v] = {-1,arr[i],p}; } else v = tr[p].son[arr[i]]; p = v; } tr[p].val++; ans += tr[p].val; } printf("%lld\n",ans); }
intmain(){ T = read(); while (T--) solve(); return0; }