#include <bits/stdc++.h>
using namespace std;
template <class T, class second>
ostream &operator<<(ostream &s, pair<T, second> &p) {
  s << '{' << p.first << ", " << p.second << '}';
  return s;
}
template <class T>
ostream &operator<<(ostream &s, vector<T> &v) {
  if (v.empty()) {
    s << "[]";
    return s;
  }
  s << '[';
  for (int i = 0; i < v.size() - 1; i++) {
    s << v[i] << ", ";
  }
  s << v.back() << ']';
  return s;
}
static mt19937 random_gen(
    chrono::high_resolution_clock::now().time_since_epoch().count());
int rand() {
  static uniform_int_distribution<int> uid(0, INT32_MAX);
  return uid(random_gen);
}
template <typename T, size_t second>
inline void operator*=(array<T, second> &a, const array<T, second> &b) {
  for (int i = 0; i < second; i++) {
    a[i] *= b[i];
  }
}
template <typename T, size_t second>
inline array<T, second> operator*(const array<T, second> &a,
                                  const array<T, second> &b) {
  array<T, second> res = a;
  res *= b;
  return res;
}
template <typename T, size_t second>
inline array<T, second> operator*(const array<T, second> &a, const int v) {
  array<T, second> res = a;
  for (int i = 0; i < second; i++) {
    res[i] *= v;
  }
  return res;
}
template <typename T, size_t second>
inline void operator%=(array<T, second> &a, const array<T, second> &b) {
  for (int i = 0; i < second; i++) {
    a[i] %= b[i];
  }
}
template <typename T, size_t second>
inline array<T, second> operator%(const array<T, second> &a,
                                  const array<T, second> &b) {
  array<T, second> res = a;
  res %= b;
  return res;
}
template <typename T, size_t second>
inline void operator+=(array<T, second> &a, const array<T, second> &b) {
  for (int i = 0; i < second; i++) {
    a[i] += b[i];
  }
}
template <typename T, size_t second>
inline array<T, second> operator+(const array<T, second> &a,
                                  const array<T, second> &b) {
  array<T, second> res = a;
  res += b;
  return res;
}
template <typename T, size_t second>
inline void operator-=(array<T, second> &a, const array<T, second> &b) {
  for (int i = 0; i < second; i++) {
    a[i] -= b[i];
  }
}
template <typename T, size_t second>
inline array<T, second> operator-(const array<T, second> &a,
                                  const array<T, second> &b) {
  array<T, second> res = a;
  res -= b;
  return res;
}
template <typename T, size_t second>
inline ostream &operator<<(ostream &s, const array<T, second> &a) {
  if (second == 0) {
    s << "[]";
  } else {
    s << '[';
    for (int i = 0; i < second - 1; i++) {
      s << a[i] << ", ";
    }
    s << a[second - 1] << ']';
  }
  return s;
}
int n;
array<int64_t, 24> pws[300005];
const array<int64_t, 24> mlt = {
    4102697LL, 3468533LL, 3904801LL, 4180607LL, 3250627LL, 4082513LL,
    3376343LL, 3665609LL, 3171277LL, 4084391LL, 4113661LL, 3193081LL,
    3938513LL, 3706433LL, 3915239LL, 3443017LL, 3402239LL, 3277777LL,
    4174727LL, 3316267LL, 3905911LL, 3263243LL, 3199171LL, 3503699LL,
};
const array<int64_t, 24> md = {
    866185961LL, 957273517LL,  941679047LL,  820397099LL, 995925493LL,
    917554819LL, 901490153LL,  1015402403LL, 866080513LL, 1032164149LL,
    945956189LL, 818808203LL,  981828797LL,  950823121LL, 1060816553LL,
    881891513LL, 1051800059LL, 937888933LL,  865977481LL, 1042799077LL,
    854373083LL, 1056322507LL, 948902657LL,  907540741LL,
};
array<int64_t, 24> mdi;
inline int64_t modpow(int64_t bs, int64_t pw, const int64_t md) {
  bs %= md;
  int64_t ans = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      ans = (ans * bs) % md;
    }
    bs = (bs * bs) % md;
  }
  return ans;
}
int main() {
  for (int i = 0; i < 24; i++) {
    pws[0][i] = 1;
  }
  for (int i = 1; i < 300005; i++) {
    pws[i] = (pws[i - 1] * mlt) % md;
  }
  for (int i = 0; i < 24; i++) {
    mdi[i] = modpow(mlt[i], md[i] - 2, md[i]);
    assert(((mdi[i] * mlt[i]) % md[i]) == 1);
  }
  for (int _t_, _q_ = 0, __ = scanf("%d", &_t_); _q_ < _t_; _q_++) {
    scanf("%d", &n);
    map<array<int64_t, 24>, int> cnts;
    array<int64_t, 24> curr;
    fill(begin(curr), end(curr), 0);
    cnts[curr] = 1;
    stack<int> stk;
    int64_t ans = 0;
    for (int i = 1; i <= n; i++) {
      int a;
      scanf("%d", &a);
      if (stk.size() && stk.top() == a) {
        curr -= ((pws[stk.size()] * a) % md);
        curr += md;
        stk.pop();
      } else {
        curr += pws[stk.size() + 1] * a;
        stk.push(a);
      }
      curr %= md;
      ans += cnts[curr];
      cnts[curr]++;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
