#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
#define inf 1e9 + 5
#define ll long long
inline int read()
{
  int X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch))
  {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch))
    X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return w ? -X : X;
}

inline void write(int x)
{
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}
void solve()
{
  int t=read();
  map<int,int>cnt;
  map<int,ll>pre;
  while(t--){
    int n=read();
    ll ans=0;
    cnt.clear();
    pre.clear();
   for(int i=1;i<=n;i++){
     int a=read();
     if(cnt[a])ans+=pre[a]*(n-i+1);
     cnt[a]++;
     pre[a]+=i;
   }
    cout<<ans<<endl;
  }
}
int main()
{
  solve();
}