#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define mod 1000000007


ll pow(ll a,ll b)
{
    ll res = 1;
    while(b>0)
    {
        if(b&1) res = res*a;
        a = a*a;
        b >>=1;
    }
    return res;
}
ll pow_mod(ll a,ll b)
{
    ll  res = 1;
    while(b>0)
    {
        if(b&1) res = (res*a)%mod;
        a = (a*a)%mod;
        b >>=1;
    }
    return res;
}
ll inv(ll a)
{
    return pow_mod(a,mod-2);
}


void solve()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    ll count=0,j=0;
    ll res=0;
    for(int i=0;i<n-2;i++)
    {
        if(j==0 || j<i+2) j=i+2;
        else 
        {
            if(count>0)count--;
        }
        while(a[j]-a[i] <= 2 && j<n) 
        {
            count++;j++;
        }
        res += (count*(count+1))/2;
    }
    cout<<res<<endl;
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}