#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<long long> X(n + 1, 0);
  vector<vector<long long>> XY(n + 1, vector<long long>(n + 1, 0)),
      XYX(n + 1, vector<long long>(n + 1, 0));
  for (int i = 0; i < n; i++) cin >> a[i];
  long long count = 0;
  for (int i = 0; i < n; i++) {
    for (int x = 1; x <= n; x++) {
      count += XYX[x][a[i]];
    }
    for (int x = 1; x <= n; x++) {
      XYX[a[i]][x] += XY[a[i]][x];
    }
    for (int x = 1; x <= n; x++) {
      XY[x][a[i]] += X[x];
    }
    X[a[i]]++;
  }
  cout << count << "\n";
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  int t;
  cin >> t;
  while (t--) solve();
}
