#include <bits/stdc++.h>
using namespace std;
const unsigned long long P1 = 1e9 + 7;
const unsigned long long P2 = 1e9 + 9;
const int N = 303123;
int n, a[N], last[N], b[N], c[N];
unordered_map<int, int> mp[N];
int main() {
  int cases = 1;
  scanf("%d", &cases);
  for (int iii = 1; iii <= cases; ++iii) {
    n = 299998;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
      a[i] = (i - 1) % 2 + 1;
      scanf("%d", &a[i]);
      last[i] = 0;
    }
    long long ans = 0;
    b[0] = 0;
    c[0] = 0;
    for (int i = 1; i <= n; ++i) {
      b[i] = i;
      c[i] = 0;
      if (mp[b[i - 1]].count(a[i])) {
        int x = mp[b[i - 1]][a[i]];
        c[i] = c[x - 1] + 1;
        ans += c[i];
        b[i] = b[x - 1];
      }
      mp[b[i]][a[i]] = i;
    }
    printf("%lld\n", ans);
    for (int i = 0; i <= n; ++i) mp[i].clear();
  }
}
