#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t; cin >> t;
	while (t--) {
		int n; cin >> n;
		map<int, ll> combinations;
		vector<int> dp(n);
		ll result = 0;
		for (int i = 0; i < n; i++) cin >> dp[i];
		for (int i = 0; i < n; i++) {
			result += combinations[dp[i]] * (n - i); // Past combinations future times we're making them
			combinations[dp[i]] += i + 1;
		}
		cout << result << '\n';
	}
}