#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int SUM = 0, ff = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    SUM = (SUM << 3) + (SUM << 1) + (ch ^ 48);
    ch = getchar();
  }
  return SUM * ff;
}
const int N = 300010;
int a[N], nxt[N];
int dp[N];
int n;
map<int, int> mp[N];
int main() {
  int test = read();
  while (test--) {
    n = read();
    for (int i = 1; i <= n; i++) a[i] = read();
    for (int i = 1; i <= n + 1; i++) {
      mp[i].clear();
      dp[i] = 0;
      nxt[i] = -1;
    }
    for (int i = n; i >= 1; i--) {
      if (mp[i + 1].count(a[i])) {
        int pos = mp[i + 1][a[i]];
        nxt[i] = pos;
        swap(mp[i], mp[pos + 1]);
        if (pos < n) mp[i][a[pos + 1]] = pos + 1;
      }
      mp[i][a[i]] = i;
    }
    long long ans = 0;
    for (int i = n; i >= 1; i--) {
      if (nxt[i] == -1) continue;
      dp[i] = dp[nxt[i] + 1] + 1;
      ans += dp[i];
    }
    printf("%lld\n", ans);
  }
  return 0;
}
