
// Problem : E2. Close Tuples (hard version)
// Contest : Codeforces - Codeforces Round #690 (Div. 3)
// URL : https://codeforces.com/contest/1462/problem/E2
// Memory Limit : 256 MB
// Time Limit : 4000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include <bits/stdc++.h>
using namespace std;

#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define pii pair<ll, ll>
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)

const ll inf=0x3f3f3f3f3f3f3f3f;
ll nCr(ll n, ll r) {
	if(n < 0 || r < 0)return 0;
	if(n < r)return 0;
	return (n * (n - 1)) / 2;
} 
int main() {
    SPEED;
    ll t;
    cin>>t;
    while(t--) {
    	ll n, m, k;
    	cin>>n;
    	m = 3;k = 2;
    	vi v(n);
    	for(ll i = 0; i < n; i++)cin>>v[i];
    	sort(all(v));
    	ll ans = 0;
    	for(ll i = 0; i < n; i++) {
    		ll x = v[i];
    		auto it = lower_bound(all(v), x + k + 1);
    		ll lft = (it - v.begin() - i - 1);
    		ans += nCr(lft, m - 1);
    	}
    	cout<<ans<<endl;
    }
    return 0;
}