#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e6 + 5, mod = 1e9 + 7;
int n, a[mxN], p[mxN][20], d[mxN], lst[mxN];
vector<int> pos[mxN];
int main() {
  ios ::sync_with_stdio(false), cin.tie(nullptr);
  int Q;
  cin >> Q;
  while (Q--) {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
      d[i] = lst[i] = 0;
      pos[i].clear();
      for (int j = 0; j < 19; ++j) p[i][j] = 0;
    }
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
      if (a[i] == a[i - 1])
        p[i][0] = i - 1, d[i] = d[i - 2] + 1;
      else if (!pos[a[i]].empty()) {
        int now = p[i - 1][0] - 1;
        for (int j = 19; j >= 0; j--) {
          if (now == -1) break;
          int x = upper_bound(pos[a[i]].begin(), pos[a[i]].end(), p[now][0]) -
                  pos[a[i]].begin() - 1;
          if (x == -1) break;
          x = pos[a[i]][x];
          while (p[now][j] > x) {
            now = p[now][j] - 1;
            x = upper_bound(pos[a[i]].begin(), pos[a[i]].end(), p[now][0]) -
                pos[a[i]].begin() - 1;
            if (x == -1) break;
            x = pos[a[i]][x];
          }
        }
        if (now > 0 && a[now] == a[i]) p[i][0] = now, d[i] = d[now - 1] + 1;
      }
      ans += d[i];
      for (int j = 1; j < 20; ++j) {
        if (!p[i][j - 1]) break;
        p[i][j] = p[p[i][j - 1] - 1][j - 1];
      }
      lst[a[i]] = i;
      pos[a[i]].push_back(i);
    }
    cout << ans << '\n';
  }
  return 0;
}
