#include <bits/stdc++.h>
using namespace std;
const int maxN = 3e5 + 10;
int a[maxN];
long long dp[maxN];
map<int, int> mm[maxN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      dp[i] = 0;
      mm[i].clear();
    }
    for (int i = 1; i <= n; i++) {
      mm[0][i] = 0;
      mm[1][i] = 0;
    }
    dp[0] = 0;
    long long ans = 0;
    int cnt = 0;
    mm[1][a[1]] = 1;
    for (int i = 2; i <= n; i++) {
      int idx = mm[i - 1][a[i]];
      if (idx == 0) {
        swap(mm[i], mm[0]);
        mm[i][a[i]] = i;
        continue;
      }
      swap(mm[i], mm[idx - 1]);
      if (idx > 0) mm[i][a[idx - 1]] = idx - 1;
      mm[i][a[i]] = i;
      if (idx > 0) dp[i] += 1 + dp[idx - 1];
      ans += dp[i];
    }
    cout << ans << endl;
  }
  return 0;
}
