#include <bits/stdc++.h>
// #include <climits>
// #include <iostream>
// #include <vector>
// #include <utility>
using namespace std;
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define fi first
#define se second
#define rep(i,L,R) for (int i = L; i < R; ++i)
#define rrep(i,R,L) for (int i = R; i > L; --i)
#define each(x, a) for (auto& x: a)
#define nndl "\n"

using ul = unsigned long;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vvi = vector<vi>;
using ii = pair<int, int>;

template<class T> void read(T& x) {
    cin >> x;
}
template <class H, class... T>
void read(H& h, T&... t) {
    cin >> h;
    read(t...);
}
template<class T> void read(vector<T>& v) {
    each(x, v)
        read(x);
}
template<class A> void write(A x) {
	cout << x;
}
template<class H, class... T> void write(const H& h, const T&... t) { 
	write(h);
	write(t...);
}
void print() {
	write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) { 
	write(h);
	if(sizeof...(t))
		write(' ');
	print(t...);
}
template<class T> void print(vector<T>& v) {
    each(x, v)
        write(x, " ");
    write("\n");
}

// code
const int maxn = 2e5;
const int m = 3;
ll dp[maxn+1][m];

void solve() {
    int n; cin >> n;
    vector<int> v(n);
    read(v);
    sort(v.begin(), v.end());

    int k = 2;

    ll res = 0;
    int i = 0;
    rep(j, 2, n) {
        while (i < j && v[i] + k < v[j]) i++;
        if (j - i + 1 >= m) {
            res += dp[j-i][m-1];
        }
    }
    
    cout << res << nndl;
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);

    // c[n][k] = c[n-1][k] + c[n-1][k-1]
    memset(dp, 0, sizeof(dp));
    rep(i, 0, maxn+1) {
        dp[i][0] = 1;
        rep(j, 1, min(i+1, m)) {
            dp[i][j] = dp[i-1][j] + dp[i-1][j-1];
        }
    }

    int t; cin >> t;
    while (t--)
        solve();
    return 0;
}