#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL),cout.tie(NULL);
ll MOD=1e9+7;

void solve()
{
    int n;
    cin>>n;
    
    map<int,vector<pair<int,ll>>> ma;
    
    for(int i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        ma[x].pb({i+1,0});
    }
    ll res=0;
    for(auto &i:ma)
    {
        int nn=i.second.size();
        for(int j=nn-1;j>=0;j--)
        {
            if(j==nn-1)
            {
                i.second[j].second=(ll)n-(ll)i.second[j].first+1ll;
            }
            else
            {
                i.second[j].second=(ll)n-(ll)i.second[j].first+1ll+i.second[j+1].second;
            }
        }
        
        for(int j=1;j<nn;j++)
        {
            
            res+=((ll)i.second[j-1].first*i.second[j].second);
        }
    }
    cout<<res;
}

int main()
{
    FAST
    
    
    int t;
    cin>>t;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
    
    #ifndef ONLINE_JUDGE
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    #endif
    return 0;
}