#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 233;
int n, T;
int f[maxn];
unordered_map<int, int> mp[maxn];
int a[maxn];
int dp[maxn];
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> T;
  while (T--) {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    for (int i = 1; i <= n + 2; ++i) {
      f[i] = i;
      mp[i].clear();
    }
    dp[n + 1] = 0;
    long long res = 0;
    for (int i = n; i; --i) {
      dp[i] = 0;
      int fa = find(i + 1);
      if (mp[fa].find(a[i]) != mp[fa].end()) {
        int t = mp[fa][a[i]];
        dp[i] = dp[t + 1] + 1;
        f[i] = find(t + 1);
      }
      res += dp[i];
      mp[f[i]][a[i]] = i;
    }
    cout << res << "\n";
  }
  return 0;
}
