#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<random>
#include<ctime>
#include<queue>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 1e5+5;
vector<int> pos[maxn];
int main() {
	int T;
    scanf("%d",&T);
    while(T--) {
		int n;
		cin>>n;
		int ct = 0;
		map<int,int> mp;
		for(int i=1;i<=n;i++){
			int x;
			scanf("%d",&x);
			if(!mp[x]) mp[x] = ++ct;
			pos[mp[x]].push_back(i);
		}
		ll ans = 0;
		vector<ll> add;
		ll sum = 0;
		for(int i=1;i<=ct;i++){
			if(pos[i].size()<=1) continue;
			add.clear();
			sum = 0;
			for(int j=0;j<pos[i].size();j++){
				sum+=pos[i][j];
				add.emplace_back(sum);
			}
			for(int j=1;j<pos[i].size();j++){
				ans+=1LL*(add[j-1])*(n-pos[i][j]+1); 
			}
		}
		for(int i=0;i<=ct;i++) pos[i].clear();
		cout<<ans<<"\n";
    }
    return 0;
}


