#include <bits/stdc++.h>
#define int long long int
#define eb emplace_back
#define pb push_back
#define vi vector<int>
#define vii vector<vi>
#define viii vector<vii>
#define vc vector<char>
#define vcc vector<vc>
#define vb vector<bool>
#define vbb vector<vb>
#define pa pair<int,int>
#define f first
#define s second
using namespace std;
const int m=1e9+7;
const int M=2e5+5;
/*int fact[M],rinv[M];
void euc_ext(int a,int b,int *x,int *y){
    if(a==0){
        *x=0,*y=1;
        return;
    }
    int x1,y1;
    euc_ext(b%a,a,&x1,&y1);
    *y=x1,*x=y1-(b/a)*x1;
}
int m_inv(int a,int p){
    int x,y;
    euc_ext(a,p,&x,&y);
    int res=(x%p+p)%p;
    return res;
}*/
void solve(){
    int n,g=3,k=2;cin>>n;
    vi arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr.begin(),arr.end());
    int ans=0;
    for(int i=0;i<n;i++){
        int targ=arr[i]+k;
        int st=i,ed=n-1,mid;
        while(st<=ed){
            mid=(st+ed)/2;
            if(arr[mid]>targ){
                ed=mid-1;continue;
            }
            st=mid+1;
        }
        if(ed-i+1<g)continue;
        int tot=ed-i;ans=ans+(tot*(tot-1))/2;
    }
    cout<<ans<<'\n';        
}
int32_t main(){
    int t;cin>>t;
    /*fact[0]=1,rinv[0]=1;
    for(int i=1;i<M;i++){
        fact[i]=(i*fact[i-1])%m;
        rinv[i]=((rinv[i-1])*(m_inv(i,m)))%m;
    }*/
    while(t--){
        solve();
    }
}