#include<bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i <= n; i++)
#define _rep(i, n, a) for(int i = n; i >= a; i--)
typedef long long LL;
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1004535809;
inline LL read(){
	LL x = 0, fl = 1; char c = getchar();
	while (c < '0' || c > '9') { if(c == '-') fl = -1; c = getchar(); }
	while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
	return x * fl;
}
int n, m, t;
LL cnt[maxn];
int main(){
	cin >> t;
	while(t--){
		cin >> n;
		memset(cnt, 0, (n + 5) * sizeof(LL));
		int x;
		rep(i, 1, n) cin >> x, cnt[x]++;
		LL ans = 0;
		rep(i, 2, n - 1) ans += cnt[i - 1] * cnt[i] * cnt[i + 1];
		rep(i, 1, n - 1) ans += cnt[i] * (cnt[i] - 1) / 2 * cnt[i + 1];
		rep(i, 1, n - 1) ans += cnt[i] * cnt[i + 1] * (cnt[i + 1] - 1) / 2;
		rep(i, 1, n - 2) ans += cnt[i] * (cnt[i] - 1) / 2 * cnt[i + 2];
		rep(i, 1, n - 2) ans += cnt[i] * cnt[i + 2] * (cnt[i + 2] - 1) / 2;
		rep(i, 1, n) ans += cnt[i] * (cnt[i] - 1) * (cnt[i] - 2) / 6;
		cout << ans << endl;
	}
}

