#include<iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
using namespace std;
#define ll long long int
#define mod (ll)1e9+7
#define ld long double
#define endl "\n"


int main()
{ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    ll n;
    cin>>n;
    vector<ll>A(n);
    for(ll i=0;i<n;i++)cin>>A[i];
   
      unordered_map<ll,ll>mp;
      for(ll i=0;i<n;i++)mp[A[i]]++;
      ll ans=0;
      for(ll i=1;i<=n;i++)
      {
        if(!mp[i])continue;
        ll cnt1=mp[i];
        ans+=cnt1*mp[i+1]*mp[i+2];
        ans+=cnt1*(mp[i+1]*(mp[i+1]-1))/2;
         ans+=cnt1*(mp[i+2]*(mp[i+2]-1))/2;
         ans+=((cnt1*(cnt1-1))/2)*mp[i+1];
          ans+=((cnt1*(cnt1-1))/2)*mp[i+2];
          if(cnt1>2)ans+=((cnt1-2)*(cnt1-1)*(cnt1))/6;

      }
      cout<<ans<<endl;

      }
    

    return 0;
}