#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
int cntUp[N][N], cntDown[N][N];
int n, a[N];
int t;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    for (int i = 1; i <= n; ++i) cntUp[0][i] = 0, cntDown[n + 1][i] = 0;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) cntUp[i][j] = cntUp[i - 1][j] + (a[i] == j);
    }
    for (int i = n; i >= 1; --i) {
      for (int j = 1; j <= n; ++j)
        cntDown[i][j] = cntDown[i + 1][j] + (a[i] == j);
    }
    long long ans = 0;
    for (int i = 2; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        ans += 1LL * cntUp[i - 1][a[j]] * cntDown[j + 1][a[i]];
      }
    }
    cout << ans << '\n';
  }
}
