#include <unordered_map>
#include <map>
#include <vector>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#include <cmath>
#include <stdio.h>
#include <string.h>
#include <numeric>
#define MAXN  1000000
#include <iostream>
#define ll long long
#define mod 1000000007
using namespace std;

 /*
Some notes while problem solving:
try to think about parity.
can you dp the problem or some part of it?
can you binary search the answer, or some part of the answer?
some greedy-Take the next choice or something, or just try the extreme ones?
	For convicing, either try some exchange arguments or try to find some counter case.
process in reverse/working backwards(Very useful for query problems)
	If query problem, try to work backwards. Or see if you could REORDER them in some way because
	mostly they are offline.
BIT problems
	Try fo see if answer could be found bit by bit, or just try to solve the answer for each
	bit independently.
 */

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int tt;
    cin>>tt;
    while(tt--){
        int n;
        cin>>n;
        ll l[n];
        for(int i=0;i<n;i++)cin>>l[i];
        ll dp[n];
        dp[0]=0;
        unordered_map<int, ll> dp2;
        dp2[l[0]]=1;
        ll ans=0;
        for(int i=1;i<n;i++){
            dp[i]=dp[i-1]+dp2[l[i]];
            dp2[l[i]]+=(i+1);
            ans+=dp[i];
        }
        cout<<ans<<"\n";
    }
    

}