#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int T, n;
string s;
int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> T;
    while(T--) {
        map <int, ll> sum;
        cin >> n;
        ll ans = 0;
        for (int i = 1; i <= n; ++i) {
            int x;
            cin >> x;
            ans += sum[x] * (n - i + 1);
            sum[x] += i;
        }
        cout << ans << '\n';
    }
    return 0;
}