#include <bits/stdc++.h>
using namespace std;
long long mod = (1000000007LL);
inline long long Mod(long long a, long long b) { return (a % b); }
inline long long poww(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
long long gcd(long long a, long long b) {
  while (b) {
    a %= b, swap(a, b);
  }
  return a;
}
void read(vector<int> &w, int n) {
  w.resize(n);
  for (int i = 0; i < n; i++) cin >> w[i];
}
void print(vector<int> &w) {
  for (int i = 0; i < (int)(w).size(); i++) {
    if (i == (int)(w).size() - 1)
      cout << w[i] << "\n";
    else
      cout << w[i] << " ";
  }
}
int prodmod(vector<int> w);
int summod(vector<int> w);
int n, m, q, k, v[300050], ans;
pair<int, int> w[300050];
string second;
vector<int> pos[300050];
vector<int> tree;
struct node {
  int sum;
  node *l, *r;
  node(int x = 0) { sum = x, l = r = NULL; }
};
node *version[300050];
void build(node *root, int a, int b) {
  if (a == b) {
    root->sum = 0;
    return;
  }
  root->l = new node(), root->r = new node();
  build(root->l, a, ((a + b) / 2)), build(root->r, ((a + b) / 2) + 1, b);
  root->sum = root->l->sum + root->r->sum;
}
void update(node *prev, node *root, int a, int b, int i, int x) {
  if (a == b) {
    root->sum = x;
    return;
  }
  if (i <= ((a + b) / 2)) {
    root->r = prev->r;
    if (!root->l) root->l = new node();
    update(prev->l, root->l, a, ((a + b) / 2), i, x);
  } else {
    root->l = prev->l;
    if (!root->r) root->r = new node();
    update(prev->r, root->r, ((a + b) / 2) + 1, b, i, x);
  }
  root->sum = root->l->sum + root->r->sum;
}
int query(node *root, int a, int b, int i) {
  if (i < a || i > b) return 0;
  if (a == b) return root->sum;
  return query(root->l, a, ((a + b) / 2), i) +
         query(root->r, ((a + b) / 2) + 1, b, i);
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> q;
  while (q--) {
    cin >> n;
    vector<int> go(n + 1);
    vector<long long> dp(n + 2);
    for (int i = 1; i <= n; i++) cin >> v[i];
    version[n + 1] = new node();
    long long ans = 0;
    build(version[n + 1], 1, n);
    for (int i = n; i >= 1; i--) {
      int j = query(version[i + 1], 1, n, v[i]);
      if (j != 0 and v[i] == v[j]) {
        go[i] = j + 1;
        version[i] = new node();
        update(version[j + 1], version[i], 1, n, v[i], i);
      } else {
        go[i] = -1;
        version[i] = new node();
        update(version[n + 1], version[i], 1, n, v[i], i);
      }
      if (go[i] == -1)
        dp[i] = 0;
      else
        dp[i] = 1 + dp[go[i]];
      ans += dp[i];
    }
    cout << ans << "\n";
  }
}
int summod(vector<int> w) {
  int curr = 0;
  for (int i = 0; i < (int)(w).size(); i++) {
    curr = (curr + w[i]) % mod;
    if (curr < 0) curr += mod;
  }
  return curr;
}
int prodmod(vector<int> w) {
  int curr = 1;
  for (int i = 0; i < (int)(w).size(); i++) {
    if (w[i] >= mod) w[i] %= mod;
    curr = (curr * w[i]) % mod;
    if (curr < 0) curr += mod;
  }
  return curr;
}
