#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;


void solve()
{
    ll n; cin>>n;
    vector<ll> v;
    for(int i=0;i<n;i++)
    {
        ll x; cin>>x;
        v.push_back(x);
    }
    sort(v.begin(),v.end());
    ll cost=0;
    for(ll i=2; i<n; ++i)
    {
        ll j=lower_bound(v.begin(),v.end(),v[i]-2)-v.begin();
        ll x=(i-j);
        cost+=(x*(x-1))/2;
    }cout<<cost<<"\n";
}



    int main()
    {
int t;
cin>>t;
while(t--)
{

solve();
    }

  }