#include <bits/stdc++.h>
using namespace std;
const int MXN = 300300;
int n, a[MXN], match[MXN], cnt[MXN];
map<int, int> prevMatch[MXN];
int main() {
  int T;
  scanf("%d", &T);
  for (int t = 1; t <= T; ++t) {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &a[i]);
      match[i] = cnt[i] = 0;
      prevMatch[i].clear();
    }
    for (int i = 2; i <= n; ++i) {
      if (a[i] == a[i - 1]) {
        match[i] = i - 1;
      } else {
        match[i] = max(0, prevMatch[i - 1][a[i]]);
      }
      if (match[i] > 1) {
        swap(prevMatch[i], prevMatch[match[i] - 1]);
        prevMatch[i][a[match[i] - 1]] = match[i] - 1;
      }
    }
    long long res = 0;
    for (int i = 2; i <= n; ++i) {
      if (match[i] == 0) continue;
      cnt[i] = cnt[match[i] - 1] + 1;
      res += cnt[i];
    }
    cout << res << "\n";
  }
  fclose(stdin);
  return 0;
}
