#include <bits/stdc++.h>
#pragma GCC target("avx2,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
template <class T1, class T2>
inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T1, class T2>
inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
inline int topbit(int x) { return x == 0 ? -1 : 31 - __builtin_clz(x); }
inline int topbit(long long x) { return x == 0 ? -1 : 63 - __builtin_clzll(x); }
inline int botbit(int x) { return x == 0 ? 32 : __builtin_ctz(x); }
inline int botbit(long long x) { return x == 0 ? 64 : __builtin_ctzll(x); }
inline int popcount(int x) { return __builtin_popcount(x); }
inline int popcount(long long x) { return __builtin_popcountll(x); }
inline int kthbit(long long x, int k) { return (x >> k) & 1; }
inline void print() { cout << "\n"; }
template <class T>
inline void print(const vector<T> &v) {
  for (auto itr = v.begin(); itr != v.end(); ++itr) cout << *itr << " ";
  print();
}
template <class T, class... Args>
inline void print(const T &x, const Args &...args) {
  cout << x << " ";
  print(args...);
}
inline void debug() {}
template <class T>
inline void debug(const vector<T> &v) {}
template <class T, class... Args>
inline void debug(const T &x, const Args &...args) {}
struct Fast_ios {
  Fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios;
template <typename S>
struct RollingHash {
 private:
  static const ull mod = (1ull << 61) - 1;
  const ull MASK30 = (1ull << 30) - 1;
  const ull MASK31 = (1ull << 31) - 1;
  const ull POSITIVIZER = mod * ((1ull << 3) - 1);
  ull base;
  vector<ull> power;
  ull Mul(ull a, ull b) {
    ull au = a >> 31;
    ull ad = a & MASK31;
    ull bu = b >> 31;
    ull bd = b & MASK31;
    ull mid = ad * bu + au * bd;
    ull midu = mid >> 30;
    ull midd = mid & MASK30;
    return (au * bu * 2 + midu + (midd << 31) + ad * bd);
  }
  ull CalcMod(ull val) {
    val = (val & mod) + (val >> 61);
    if (val >= mod) val -= mod;
    return val;
  }

 public:
  static inline ull generate_base() {
    mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<ull> rand(1, RollingHash::mod - 1);
    return rand(mt);
  }
  RollingHash(int N, ull base) : power(N + 1, 1), base(base) {
    for (int i = 0; i < N; ++i) {
      power[i + 1] = CalcMod(Mul(power[i], base));
    }
  }
  vector<ull> gethash(const S &s) {
    int sz = s.size();
    vector<ull> ret(sz + 1);
    for (int i = 0; i < sz; ++i) {
      ret[i + 1] = CalcMod(Mul(ret[i], base) + s[i] + 1);
    }
    return ret;
  }
  ull getrange(const vector<ull> &hash, int l, int r) {
    if (l >= r) return 0;
    return CalcMod(hash[r] + POSITIVIZER - Mul(hash[l], power[r - l]));
  }
  ull getval(const S &s) {
    ull ret = 0;
    for (int i = 0; i < (int)s.size(); ++i) {
      ret = CalcMod(Mul(ret, base) + s[i] + 1);
    }
    return ret;
  }
  ull connect(ull hl, ull hr, int rlen) {
    return CalcMod(CalcMod(Mul(hl, power[rlen])) + hr);
  }
  int LCP(const vector<ull> &a, const vector<ull> &b, int l1, int r1, int l2,
          int r2) {
    int len = min(r1 - l1, r2 - l2);
    int low = -1, high = len + 1;
    while (high - low > 1) {
      int mid = (low + high) / 2;
      if (getrange(a, l1, l1 + mid) == getrange(b, l2, l2 + mid))
        low = mid;
      else
        high = mid;
    }
    return low;
  }
};
void solve() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < (N); ++i) cin >> A[i];
  ull base = RollingHash<vector<int>>::generate_base();
  RollingHash<vector<int>> RH(N, base);
  vector<ull> RA = RH.gethash(A);
  vector<int> sta;
  vector<ull> hash;
  map<ull, int> dic;
  ll ans = 0;
  dic[0]++;
  hash.emplace_back(0);
  for (int i = 0; i < (N); ++i) {
    if (sta.empty()) {
      sta.emplace_back(A[i]);
      ull val = RH.getrange(RA, i, i + 1);
      ans += dic[val];
      dic[val]++;
      hash.emplace_back(val);
    } else if (sta.back() == A[i]) {
      sta.pop_back();
      hash.pop_back();
      ull val = hash.back();
      ans += dic[val];
      dic[val]++;
    } else {
      sta.emplace_back(A[i]);
      ull val = RH.connect(hash.back(), RH.getrange(RA, i, i + 1), 1);
      ans += dic[val];
      dic[val]++;
      hash.emplace_back(val);
    }
  }
  cout << ans << ln;
}
int main() {
  int Q;
  cin >> Q;
  while (Q--) {
    solve();
  }
}
