#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <functional>  
#include <map>
#include <queue> 
#include <string>  
#include <deque>
#include <set>
#include <bitset>
#include <cstring>
#include <unordered_map>
//#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define p_b push_back
#define all(n) n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
#define mk_p make_pair
typedef long long ll;
const char sl='\n';
const int Msize = 105;
//// C....
const int N = 2e5;

int acum[N+1];
ll carmen[N+1];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

	carmen[3] = 1;
	for(int i = 4;i<N+1;++i)
	{
		carmen[i] = carmen[i-1] + (1LL*(i-2)*(i-1)/2);
	}
	int t; cin >> t;
	while(t--)
	{
		int n; cin >> n;
		for(int i =1;i<=n;++i)
		{
			acum[i] = 0;
		}
		for(int i = 0;i<n;++i)
		{
			int x; cin >> x;
			acum[x]++;
		}
		ll ans =0;
		for(int i = 1;i<=n-2;++i)
		{
			ans += (acum[i]*acum[i+1]*acum[i+2]);
		}
		for(int i = 1;i<=n-1;++i)
		{
			ans += (((1LL*acum[i]*(acum[i]-1))/2) * acum[i+1]);
			ans += (((1LL*acum[i+1]*(acum[i+1]-1))/2) * acum[i]);
		}
		for(int i = 1;i<=n-2;++i)
		{
			ans += (((1LL*acum[i]*(acum[i]-1))/2) * acum[i+2]);
			ans += (((1LL*acum[i+2]*(acum[i+2]-1))/2) * acum[i]);
		}
		for(int i = 1;i<=n;++i)
		{
			if(acum[i])
			{
				ans+=carmen[acum[i]];
			}
		}
		cout<<ans<<sl;
	}
	return 0;				
}