#include <bits/stdc++.h>
using namespace std;
const int N = 3010, M = 1010;
int T;
int n, a[N];
int lcnt[N][N], rcnt[N][N];
int main() {
  cin >> T;
  while (T--) {
    memset(lcnt, 0, sizeof lcnt);
    memset(rcnt, 0, sizeof rcnt);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) lcnt[i][j] = lcnt[i - 1][j];
      lcnt[i][a[i]]++;
    }
    for (int i = n; i >= 1; i--) {
      for (int j = 1; j <= n; j++) rcnt[i][j] = rcnt[i + 1][j];
      rcnt[i][a[i]]++;
    }
    long long res = 0;
    for (int j = 1; j <= n; j++)
      for (int k = j + 1; k <= n; k++)
        res += lcnt[j - 1][a[k]] * rcnt[k + 1][a[j]];
    cout << res << '\n';
  }
  return 0;
}
