#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100001] = { 0 };
int main() {
	// your code goes here
	int t;
	cin>>t;
	ll sum;
    while(t--)
    {
        ll n;
        cin>>n;
        ll sum=0;
        for(ll i=0;i<n;i++)
        {
            cin>>a[i];
        }
        map <ll,ll> m;
        for (int j=0;j<n;j++)
        {
            sum+=m[a[j]]*(n-j);
            
            m[a[j]] += j+1;
        }
       cout<<sum<<endl;
        
    }
	return 0;
}