#include <iostream>
#include <bits/stdc++.h>
#define forn(i,n)for(int i=0;i<n;i++)
#define forna(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define maap map<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff first
#define ss second
#define INF 1000000
#define MAX 500005
typedef long long ll;
using namespace std;
#define all(v) v.begin(),v.end()
#define pi pair<int,int>
//cout<<"Case #"<<x<<": "<<ans<<endl;
int a[MAX];
ll mod = 1e9+7;

ll ncr(ll n,ll r){
    r = min(r,n-r);
    if(r==0) return 1;
    if(r==1) return n;
    if(r==2) return (n*(n-1))/2;
    if(r==3){
        ll ans= n*(n-1);
        ans /=2;
        ans *= (n-2);
        ans /= 3;
        return ans;
    }
}

void solve(int cases){
  int n;cin>>n;
  int k=2,m=3;
  //cin>>m>>k;
  forn(i,n) cin>>a[i];
  sort(a,a+n);

//cout<<"jaha  "<<nCrModPFermat(4,2)<<endl;

  ll ans=0;
  //ll mod = 1e9+7;
  int l=0,r=0;
  while(l<=n-m){
    while(r<n && r-l+1<m) r++;
    if(r==n) break;
    int mi = a[l];
    if(a[r]-mi>k) {l++;continue;}
    while(r<n-1 && a[r+1] - mi <= k) r++;
    ll rem  = r-l+1-1;
    ll gg = ncr(rem,m-1);
    ans += gg;
   // ans %= mod;
    //cout<<l<<" "<<r<<" "<<ans<<"\n";
    l++;

  }
  cout<<ans<<"\n";

}

int main()
{
  IOS
  int cases=1;
  int t=1;
  cin>>t;
  while(t--){
    solve(cases++);
  }
}


