#include "bits/stdc++.h"

using namespace std;
using ll = long long;

#define fo(i,a,b) \
    for(int i = a; i < b; i++)
#define Fo(i,a,b) \
    for(int i = a; i >= b; i--)
#define fastio \
    ios_base::sync_with_stdio(0); \
    cin.tie(0); \
    cout.tie(0);

void solve() {

    ll n,x;
    cin >> n;

    map<ll,ll> f;

    fo(i,0,n) {
        cin >> x;
        f[x]++;
    }

    ll ans = 0;

    for(auto &it: f) {
        x = it.second;
        ans += 1LL*(x*(x-1)*(x-2))/6;
        auto it1 = f.find(it.first+1);
        auto it2 = f.find(it.first+2);
        if(it1 != f.end()) {
            ans += 1LL*((x*(x-1))/2)*f[it.first+1];
            ans += 1LL*(f[it.first+1]*(f[it.first+1]-1)/2)*x;
        }
        if(it2 != f.end()) {
            ans += 1LL*((x*(x-1))/2)*f[it.first+2];
            ans += 1LL*(f[it.first+2]*(f[it.first+2]-1)/2)*x;
        }
        if(it1 != f.end() and it2 != f.end()) {
            ans += 1LL*x*f[it.first+1]*f[it.first+2];
        }
    }
    
    cout << ans;
}       

int main() {

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
     
    fastio;

    int t = 1;
    cin >> t;

    while(t--) {
        solve();
        cout << '\n';
    } 

    return 0;
}