#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0) 
int mod = 1e9 + 7;
#define pb push_back
#define vi vector<int>


int32_t main(){
    fast_io;
    int t;cin>>t;
    while(t--){
      int n;cin>>n;
      vi arr(n);
      map<int,vector<int>> mp;
      for(int i=0;i<n;i++){
        cin>>arr[i];
        mp[arr[i]].pb(i);
      }
      /*for(auto it: mp){
          cout<<it.first<<"->";
          for(int i=0;i<it.second.size();i++){
              cout<<it.second[i]<<" ";
          }
          cout<<endl;
      }*/
      int ans = 0;

      for(auto it: mp){
        vi v = it.second;
        int suffix[v.size()];

        for(int i=0;i<v.size();i++){
          suffix[i] = n - v[i];
        }
        int a = v.size();
        for(int i=a-2;i>=0;i--){
            if(i<0){
                break;
            }
          suffix[i] = suffix[i] + suffix[i + 1];
          //cout<<suffix[i]<<" "<<i<<endl;
        }


        for(int i=0;i<v.size()-1;i++){
          ans = ans + ((v[i]+1)*suffix[i + 1]);
        }
      }
      cout<<ans<<endl;
    }
    return 0;
}
