#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
long long n;
void solve() {
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<long long> st(n * n + n + 1);
  long long ans = 0;
  for (long long j = n - 1; j >= 0; j--) {
    long long k = j + 1;
    for (long long l = k + 1; l < n; l++) {
      st[a[k] * n + a[l]]++;
    }
    for (long long i = 0; i < j; i++) {
      ans += st[a[i] * n + a[j]];
    }
  }
  cout << ans << '\n';
}
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
}
