#include <bits/stdc++.h>
using namespace std;
void testcase() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < (n); ++i) cin >> A[i];
  long long zigzags = 0;
  long long cntLeft[n + 1], cntRight[n + 1];
  memset(cntLeft, 0, (n + 1) * sizeof(long long));
  for (int j = 0; j < (n); ++j) {
    if (j > 0) {
      cntLeft[A[j - 1]]++;
    }
    memset(cntRight, 0, (n + 1) * sizeof(long long));
    for (int k = n - 1; k > j; k--) {
      if (k < n - 1) {
        cntRight[A[k + 1]]++;
      }
      zigzags += cntLeft[A[k]] * cntRight[A[j]];
    }
  }
  cout << zigzags << '\n';
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  int t;
  cin >> t;
  for (int i = 0; i < (t); ++i) testcase();
}
