#include <bits/stdc++.h>
using namespace std;
using ll = long long;
map< ll , vector<ll> > mp;
void solve()
{
    mp.clear();
    ll n;
    cin >> n;
    for(int i = 1 ; i <= n ; i++)
    {
        ll x;
        cin >>  x;
        mp[x].push_back(i);
    }
    ll ans= 0;
    for(auto x : mp)
    {
        ll sz = x.second.size();
        ll pre[sz];
        pre[sz-1] = n-x.second.back() + 1;
        for(int i = sz - 2 ; i >= 0 ; i--)
        {
            pre[i] = pre[i+1] + (n - x.second[i]+1);

        }
        for(int i = 0 ; i < sz - 1 ; i++)
        {
            ans += (x.second[i])*(pre[i+1]);
        }
    }
    cout << ans << endl;
}

int main() 
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("ou.txt" , "w" , stdout);
    #endif
    ll tc;
    cin >> tc;
    while(tc--)
    {
        solve();
    }
    return 0;
}