------
## 最终结论
```python
def count_tuples(test_cases):
    results = []
    
    for case in test_cases:
        n, a = case
        count_j_l = {}
        count_i_k = {}
        
        # Count pairs (j, l) where values are equal
        for j in range(n):
            for l in range(j + 1, n):
                if a[j] == a[l]:
                    if (j, l) not in count_j_l:
                        count_j_l[(j, l)] = 0
                    count_j_l[(j, l)] += 1
        
        # Count pairs (i, k) where values are equal
        for i in range(n):
            for k in range(i + 1, n):
                if a[i] == a[k]:
                    if (i, k) not in count_i_k:
                        count_i_k[(i, k)] = 0
                    count_i_k[(i, k)] += 1
        
        total_count = 0
        
        # Check conditions and calculate total_count
        for (i, k) in count_i_k:
            for (j, l) in count_j_l:
                if i < j < k < l:
                    total_count += count_i_k[(i, k)] * count_j_l[(j, l)]
        
        results.append(total_count)
    
    return results

# Example usage:
t = 2
test_cases = [
    (5, [2, 2, 2, 2, 2]),
    (6, [1, 3, 3, 1, 2, 3])
]

print(count_tuples(test_cases))
```