#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
struct fenwick_tree {
  int n;
  vector<int> data;
  fenwick_tree(int _n) : n(_n), data(vector<int>(n)) {}
  void update(int at, int by) {
    while (at < n) data[at] += by, at |= at + 1;
  }
  int query(int at) {
    int res = 0;
    while (at >= 0) res += data[at], at = (at & (at + 1)) - 1;
    return res;
  }
  int rsq(int a, int b) { return query(b) - query(a - 1); }
};
int main() {
  cin.sync_with_stdio(false);
  int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<long long> a(n);
    for (auto i = (0); i < (n); ++i) cin >> a[i];
    fenwick_tree fw(n);
    for (auto i = (0); i < (n); ++i) {
      for (auto j = (i + 1); j < (n); ++j) {
        if (a[i] != a[j]) continue;
        fw.update(i + 1, 1);
        fw.update(j, -1);
      }
    }
    long long ans = 0;
    for (auto i = (0); i < (n); ++i) {
      for (auto j = (i + 1); j < (n); ++j) {
        if (a[i] != a[j]) continue;
        fw.update(i + 1, -1);
        fw.update(j, 1);
      }
      for (auto j = (i + 1); j < (n); ++j) {
        if (a[i] != a[j]) continue;
        ans += fw.rsq(0, j);
      }
    }
    cout << ans << '\n';
  }
}
