#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long int INF = 1e12;
const int N = 1e5 + 5;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    long long int ans = 0;
    long long int left[n + 5], right[n + 5];
    for (int i = 0; i < n + 4; i++) left[i] = right[i] = 0;
    for (int j = 0; j < n; j++) {
      memset(right, 0, sizeof(right));
      if (j != 0) left[a[j - 1]]++;
      for (int k = n - 1; k > j; k--) {
        if (k != n - 1) right[a[k + 1]]++;
        ans += left[a[k]] * right[a[j]];
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
