import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	foreach (test; 0..readln.strip.to !(int))
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		auto num = new int [] [] (n, n + 1);
		foreach (i; 0..n)
		{
			foreach (j; 0..n)
			{
				num[i][j + 1] = num[i][j] + (a[i] == a[j]);
			}
		}
		long res = 0;
		foreach (i; 1..n)
		{
			foreach (j; i + 1..n - 1)
			{
				res += num[j][i] *
				    (num[i][n] - num[i][j + 1]);
			}
		}
		writeln (res);
	}
}
