#include <bits/stdc++.h>
using namespace std;
long long t, n;
long long a[3005];
long long dp[3005][3005];
long long cnt[3005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    for (long long i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    for (long long i = 1; i <= n; ++i) {
      cnt[i] = 0;
    }
    for (long long i = 2; i <= n - 1; ++i) {
      ++cnt[a[i - 1]];
      for (long long j = i + 2; j <= n + 1; ++j) {
        dp[i][j] = 0;
      }
      for (long long j = i + 2; j <= n + 1; ++j) {
        dp[i][j] = dp[i][j - 1] + cnt[a[j - 1]];
      }
    }
    long long ans = 0;
    for (long long i = 2; i <= n; ++i) {
      for (long long j = i + 2; j <= n; ++j) {
        if (a[i] != a[j]) {
          continue;
        }
        ans += dp[i][j];
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
