#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long mod = 998244353, M = 1e9 + 7, INF = 1e18;
const long long N = 1e6 + 6;
void solve() {
  long long n, ans = 0;
  cin >> n;
  vector<long long> a(n), f(n + 1), g(n + 1);
  for (long long &e : a) cin >> e, g[e]++;
  for (long long j = 0; j < n; j++) {
    g[a[j]]--;
    auto h = g;
    for (long long k = j + 1; k < n; k++) {
      h[a[k]]--;
      ans += f[a[k]] * h[a[j]];
    }
    f[a[j]]++;
  }
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  for (int it = 1; it <= t; it++) {
    solve();
  }
  return 0;
}
