#include<bits/stdc++.h>
using namespace std;

#define int long long int

void solve(){
    int n;
    cin>>n;
    
    vector<int> a(n);
    for(int i = 0 ; i < n ;i++) cin>>a[i];
    
    int sumweight = 0;
    unordered_map<int,int> pos;
    
    for(int i = 0 ; i < n ;i++){
        sumweight += (pos[a[i]])*(n - i);
        pos[a[i]] += (i  + 1);
    }
    
    cout<<sumweight<<endl;
}


int32_t main(){
    int t;
    cin>>t;
    
    while(t--){
        solve();
    }
}