#include<bits/stdc++.h>
#define mx                          100005
#define lli                         long long int
#define ulli                        unsigned long long int
#define mset(a,b)                   memset(a, b, sizeof(a))
#define infile                      freopen("in.txt", "r", stdin);
#define outfile                     freopen ("out.txt","w",stdout);
#define fileclose                   fclose (stdin); fclose (stdout);
#define test_case                   lli T; cin>>T;for(lli t=1;t<=T;t++)
#define scani(x)                    scanf("%d",&x);
#define printi(x)                   printf("%d\n",x);
#define scanli(x)                   scanf("%lld",&x);
#define printli(x)                  printf("%lld\n",x);
#define frep(i,from,to)             for(lli i=from;i<=to;i++)
#define frev(i,from,to)             for(lli i=from;i>=to;i--)

using namespace std;

int main()
{

//    infile
//    outfile
    test_case
    {
        lli n,x,ans=0;
        cin>>n;
        map<lli,lli>m;
        frep(i,1,n)
        {
            cin>>x;
            ans+=(n-i+1)*m[x];
            m[x]+=i;

        }
        cout<<ans<<"\n";

    }

    fileclose
    return 0;
}
