#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
long long t, it, n, i, a[5009], res, j, pre[3009][3009], suf[3009][3009];
int main() {
  cin >> t;
  for (it = 1; it <= t; it++) {
    res = 0;
    cin >> n;
    for (i = 1; i <= n; i++) {
      cin >> a[i];
    }
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= n; j++) {
        pre[i][j] = pre[i - 1][j];
      }
      pre[i][a[i]]++;
    }
    for (i = n; i >= 1; i--) {
      for (j = 1; j <= n; j++) {
        suf[i][j] = suf[i + 1][j];
      }
      suf[i][a[i]]++;
    }
    for (i = 1; i <= n; i++) {
      for (j = i + 1; j <= n; j++) {
        res += pre[i - 1][a[j]] * suf[j + 1][a[i]];
      }
    }
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= n; j++) {
        pre[i][j] = 0;
        suf[i][j] = 0;
      }
    }
    cout << res << '\n';
  }
}
