#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> a(n);
    vector<vector<long long> > cnt(n + 1);
    vector<vector<long long> > prefix(n + 1, vector<long long>(n, 0));
    for (int i = (0), ThxMK = (n); i < ThxMK; ++i) {
      cin >> a[i];
      cnt[a[i]].emplace_back(i);
      prefix[a[i]][i] = 1;
      for (int j = 1; i and j <= n; j++) prefix[j][i] += prefix[j][i - 1];
    }
    long long sol = 0;
    for (int i = 0; i + 3 < n; i++) {
      long long sum = 0;
      for (int j = i + 2; j + 1 < n; j++) {
        sum += prefix[a[j - 1]][n - 1] - prefix[a[j - 1]][j];
        sum -= (prefix[a[j]][j - 2] - prefix[a[j]][i]);
        if (a[i] == a[j]) {
          sol += sum;
        }
      }
    }
    cout << sol << '\n';
  }
  return 0;
}
