#include "bits/stdc++.h"
#define pb(x) push_back(x)
#define fil(x, y) memset(x, y, sizeof(x))
#define ll long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define mp(x, y) make_pair(x,y)
#define inf 536870911
#define infll 2305843009213693951
#define M 1000000007
#define N 100007
#define sz size
#define sm 0.0000007
#define ins insert
#define ers erase
#define all(k) k.begin(), k.end()
#define cnt count
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
using namespace std;


ll ara[N];
vector <int> adj[N + 10];
int main()
{
    fastio;
    int t, o = 0;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        map <int, int> amio;
        int f = 1;
        for(int i = 0;i < n;i++)
        {
            cin >> ara[i];
            if(amio[ara[i]] == 0)
            {
                amio[ara[i]] = f;
                f++;
            }
            adj[amio[ara[i]]].pb(i);
        }
        ll ans = 0;
        for(int i = 1;i <= f;i++)
        {
            ll sum[adj[i].sz()];
            if(adj[i].sz() == 0)
                continue;
            for(int j = adj[i].sz()-1;j >= 0;j--)
            {
                if(j == adj[i].sz() - 1){
                    sum[j] = n - adj[i][j];
                }
                else
                {
                    sum[j] = sum[j + 1] + n - adj[i][j];
                    ans += (adj[i][j] + 1)*sum[j + 1];
                }
            }
        }
        cout << ans << endl;
        for(int i = 1;i <= f;i++)
            adj[i].clear();
    }
    return 0;
}