#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 998244353
#define MAX 100005
int main()
{

	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int T;
    cin>>T;
    while(T--){
    	int n, x;
    	cin>>n;
    	ll ans = 0;
    	map <int, vector <int> > m;
    	for(int i = 0; i < n; ++i){
    		cin>>x;
    		m[x].pb(i + 1);
    	}
    	for(auto it : m){
    		vector <int> v = it.second;
    		long long prefix = 0;
    		for(int i = 0; i < v.size(); ++i){
    			ans += prefix * (ll)(n - v[i] + 1);
    			prefix += (ll)v[i];
    		}
    	}
    	cout<<ans<<'\n';
    }
}
