#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
 
ll mod = 1e9+7;

#define MAXN   10000001
int spf[MAXN];

void sieve()
{
    spf[1] = 1;
    for (int i=2; i<MAXN; i++)
  
        spf[i] = i;
    for (int i=4; i<MAXN; i+=2)
        spf[i] = 2;
  
    for (int i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (int j=i*i; j<MAXN; j+=i)
  
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}

ll pwr(ll x, ll y) {
	ll res = 1;
	x = x;
	while (y > 0) {
		if (y&1) res = (res*x)%mod;
 
		y = y>>1;
		x = (x*x)%mod;
	}
	return res;
}

int main() 
{ 	
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		map<int,vector<ll>>m;
		for(int i=0;i<n;i++)
		{
			int x;
			cin>>x;
			m[x].push_back(i);
		}
		ll ans = 0;
		for(auto x:m)
		{
			ll suffix[x.second.size()];
			suffix[x.second.size()-1]=0;
			for(int i=x.second.size()-2;i>=0;i--)
			{
				suffix[i] = suffix[i+1]+n - x.second[i+1];
			}
			for(int i=0;i<x.second.size();i++)
			{
				ans = ans + (x.second[i]+1)*(suffix[i]);
			}
			
		}
		cout<<ans<<endl;
	}
				
	
} 































