#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;

const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int INF = INT_MAX;
const long long INFLL = (long long)1e18;
const double PI = acos(-1.0);

template<class T> T gcd(T a, T b){
    return b ? gcd(b, a % b) : a;
}
template<class T> T lcm(T a, T b){
    return a / gcd(a, b) * b;
}

const int N = (int)2e5 + 5;
const int P = 1 << 18;

int T;
int a[N];
      
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	
	ios::sync_with_stdio(false);
	cout.setf(ios::fixed | ios::showpoint);
	cout.precision(8);
	
	cin >> T;
	while(T--){
		int n, m = 3, k = 2;
		cin >> n;
		for(int i = 0; i < n; i++){
			cin >> a[i];
		}
		sort(a, a + n);
		ll ans = 0;
		for(int i = 0; i < n; i++){
			int cnt = 0;
			int l = i + 1, r = n - 1;
			while(r - l > 1){
				int mid = (l + r) / 2;
				if(a[mid] - a[i] > k) r = mid;
				else l = mid;
			}
			if(a[r] - a[i] <= k) l = r;
			cnt = l - i;
			if(cnt < 2) continue;
			ll hlp = 1LL * cnt * (cnt - 1);
			hlp /= 1LL * 2;
			ans += hlp;
		}
		cout << ans << endl;
	}
	
#ifndef ONLINE_JUDGE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}