#include <bits/stdc++.h>
#define ll long long int
using namespace std;
bool subArrayExists(int arr[], int n)
{
    unordered_set<int> sumSet;
 
    // Traverse through array
    // and store prefix sums
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum += arr[i];
 
        // If prefix sum is 0 or
        // it is already present
        if (sum == 0
            || sumSet.find(sum)
            != sumSet.end())
            return true;
 
        sumSet.insert(sum);
    }
    return false;
}
int main() {
  int t;
  cin >> t;while(t--){
  ll n, i, j, count = 0;
  cin >> n;
  map<ll, ll> a;
  ll b[n];
  ll anss = 0;
  for (ll i = 0; i < n; i++) {
    cin >> b[i];
    if (a.count(b[i]) == 0) {
      a[b[i]] = i + 1;
    } else {
      anss += a[b[i]] * (n - i);
      a[b[i]] += i + 1;
    }
  }
  cout << anss << endl;
  }
  return 0;
}