#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
typedef pair<int,int> PII;
const int maxn = 1e5+5;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
template<typename T>void in(T &x) {
    char ch = getchar();bool flag = 0;x = 0;
    while(ch < '0' || ch > '9') flag |= (ch == '-'), ch = getchar();
    while(ch <= '9' && ch >= '0') x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
    if(flag) x = -x;return ;
}
int n,m,k,T;
int A[maxn],B[maxn],C[maxn];
bool cmp(int x,int y){
	if(A[x] == A[y])	return x > y;
	return A[x] < A[y];
}
ll dp[maxn];
map <int,ll> M;
signed main(){	
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
	in(T);
	while(T--){
		M.clear();
		in(n);
		for(int i = 1;i <= n;i++){
			in(A[i]);
		}
		ll ans = 0;
		for(int i = 1;i <= n;i++){
			dp[i] = dp[i-1];
			if(M.count(A[i]))	dp[i] += M[A[i]];
			
			M[A[i]] += i;
			ans += dp[i];
		}
		cout << ans << endl;
	}
	return 0;
}
