#include <bits/stdc++.h>
#define FOR(i, j, k) for(int i = j; i < k; i ++)
#define FORE(i, j, k) for(int i = j; i <= k; i ++)
#define FORD(i, j, k) for(int i = j; i >= k; i --)
#define mp make_pair
#define ll long long
//#define f first
//#define s second
//#define int long long
using namespace std;

const int MOD=1e9+7;
const int N = 200005;

int n, a[N];
ll res = 0;
ll dp[N], dp1[N];
map < int, int > pre;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    #define task""
//    freopen(task".inp","r",stdin);
//    freopen(task".out","w",stdout);
    int T;
    cin >> T;
    while(T --)
    {
        cin >> n;
        FORE(i, 1, n) cin >> a[i], dp[i] = dp1[i] = 0;
        pre.clear();
        res = 0;
        FORE(i, 1, n)
        {
            dp[i] = dp[i - 1];
            int x = pre[a[i]];
            if(x > 0)
            {
                dp1[i] = dp1[x] + x;
                dp[i] += dp1[i];
            }
            pre[a[i]] = i;
            res += dp[i];
        }
        cout << res << "\n";
    }

    return 0;
}
