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

#define int         long long
#define pb          push_back
#define m_p         make_pair
#define fi          first
#define ss          second
#define in          insert
#define clean       cout.flush()
#define pf          push_front
#define all(x)      x.begin(),x.end()
#define loop(a,b)   for(int i=(a);i<=(b);i++)
#define nloop(a,b)  for(int j=(a);j<=(b);j++)
#define loop1(a,b)  for(int i=(a); i<(b);i++)

//Here I have defined all the things.....have you any problem?
typedef pair<int,int>       pii;
typedef double              dl;
typedef unsigned long long  ull;
typedef vector<int>         vi;
typedef vector<pii>         vpii;

const int INF_MAX  = 1e18;
const int INF_MIN  = (1e18)*(-1);
const int mod      = 1e9+7;
const int N        = 2e5+10;
bool chex(int n){
    int k=sqrt(n);
    int k1=ceil(sqrt(n));
    if(k==k1) return true;
    else return false;
}
/*set<int>s;
void make(){
    for(int i=0;i<=60;i++){
        s.in(1<<i);
    }
}*/
void Solve(){
   int n; cin>>n;
   int ara[n+10];
   for(int i=1;i<=n;i++){
       cin>>ara[i];
   }
   map<int,int>sum;
   int ans=0;
   for(int i=1;i<=n;i++){
       int k=(n-i+1)*sum[ara[i]];
       ans+=k;
       sum[ara[i]]+=i;
   }
   cout<<ans<<endl;
} 
    

int32_t main(){
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    //make();
    int Test=1;
    cin>>Test;
    while(Test--){
        Solve();
    }
    return 0;
}
/* 20 11 3 8 4 1 9 6 1 13 9 5 11 5 4 19 12 8 13 5 4 8 4 7 9 2 10 13 3 7 16 7 14 19 4*/
