#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define vi          vector<int>
#define endl        "\n"
#define ld          long double
#define pb          push_back
#define all(v)      v.begin(),v.end()
#define vvi         vector<vector<int>>
#define rep(i,j,k)  for(int i=j; i<k; i++)
#define showvec(v)  for(auto it : v){cout << it << " ";}cout << endl;
#define IamSpeed    ios_base::sync_with_stdio(false); cin.tie(NULL);

const int mod = 1e9+7;

int getMSB(int x){ return (int)log2(x); }
 int getsum(int x) {return x*(x+1)/2 ; }
void solve(){
    int n, sum = 0;
    cin >> n;
    vi v(n), dp(n,0);
    for(auto &it : v) cin >> it;
    map<int,int> cnt;
    
    for(int i = 0; i < n; i++){
        dp[i] = ((i == 0)?0:dp[i-1]) + cnt[v[i]];
        cnt[v[i]] += (i+1);
    }

    rep(i,0,n) sum += dp[i];
    cout << sum << endl;
    

}
 
int32_t main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE
    IamSpeed;
    int t;
 
    
    // rep(i, 0, 16)cout << pref[i] << " ";
    // cout << endl;
    cin >> t; 
    while(t--){ solve(); }
     // solve();
 
 
 
    
    return 0;
}