#include <bits/stdc++.h>
using namespace std;

#define IO          ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int         long long
#define double      long double
#define vi          vector<int>
#define vvi         vector<vi>
#define pii         pair<int, int>
#define vii         vector<pii>
#define endl        '\n'
#define pb          emplace_back
#define mkpr        make_pair
#define all(v)      (v).begin(), (v).end()
#define rall(v)     (v).rbegin(), (v).rend()
#define mod         1000000007

void solve() {
	int n;
	cin >> n;
	vi a(n), cnt(n + 1);
	for (auto &it : a) {
		cin >> it;
		cnt[it]++;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int x = a[i];
		cnt[x]--;
		int curr = 0;
		for (int rep = x - 2; rep <= x + 2; rep++) {
			for (int repp = rep; repp <= x + 2; repp++) {
				if (rep <= 0 || repp <= 0 || rep > n || repp > n)
					continue;
				if (max({x, rep, repp}) - min({x, rep, repp}) > 2)	continue;
				if (rep == repp)	curr += cnt[rep] * (cnt[rep] - 1) / 2;
				else	curr += cnt[rep] * cnt[repp];
			}
		}
		ans += curr;
	}
	cout << ans << endl;
}

signed main() {
	IO;
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}
