#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll a[n+1];
        map<ll,ll>mp;
        for(ll i=1; i<=n; i++)
        {
            cin>>a[i];
            mp[a[i]]++;
        }
        vector<ll>vec;
        vec.push_back(0);
        for(ll i=1; i<=n; i++)
        {
            ll val=(i*(i+1))/2;
                vec.push_back(val+vec[i-1]);
        }
         // for(auto x:vec)
           // cout<<x<<" ";
        bool flag=true;
        ll pre=0,ans=0;
        for(ll i=1; i<=n; i++)
        {
            ll tot=0;
            if(mp[i])
            {
                tot+=mp[i]+mp[i+1]+mp[i+2];
                ll besi=max(0LL,tot-2);
                ll val=vec[besi]-vec[pre];
                pre=mp[i+1]+mp[i+2];
                pre=max(pre-2,0LL);
               // cout<<val<<" ";
                ans+=max(0LL,val);
            }
        }
        cout<<ans<<"\n";
    }
}
