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

int a[200005];
map<int,int>mp;
int sum[200005];
signed main(){
	ios::sync_with_stdio(false);
	int t;cin>>t;
	while(t--){
		int n;cin>>n;
		int ans = 0;
		mp.clear();
		for(int i = 1; i <= n; ++i) cin>>a[i];
		for(int i = n; i >= 1; --i) {
			ans+=(i) * mp[a[i]];
			mp[a[i]]+=(n-i+1);
		}
		cout<<ans<<'\n'; 
	}
	return 0;
}