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