#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
int a[N];
vector<int> num;
vector<int> pos[N];
int pre[N];
int main(){
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--){
        int i;
        int n;
        cin>>n;
        num.clear();
        for(i=1;i<=n;i++){
            cin>>a[i];
            num.push_back(a[i]);
        }
        sort(num.begin(),num.end());
        num.erase(unique(num.begin(),num.end()),num.end());
        int cnt=num.size();
        for(i=0;i<cnt;i++){
            pos[i].clear();
        }
        ll ans=0;
        for(i=1;i<=n;i++){
            a[i]=lower_bound(num.begin(),num.end(),a[i])-num.begin();
            pos[a[i]].push_back(i);
        }
        for(i=0;i<cnt;i++){
            ll sum=0;
            for(int j=0;j<pos[i].size();j++){
                int d=n-pos[i][j]+1;
                ans+=d*sum;
                sum+=pos[i][j];
            }
        }
        cout<<ans<<endl;
    }
	return 0;
}
