#include <stdio.h>
// #include <iostream>
#include <algorithm>
// #include <cmath>
// #include <string>
// #include <string.h>
// #include <vector>
// #include <bits/stdc++.h>
using namespace std;

// const int INF32 = 2000000000;
// const int INF64 = 2000000000000000000;
// const int MOD17 = 1000000007;

int tc, n, arr[200002];

int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d", &tc);
	while(tc--){
		scanf("%d", &n);
		for(int i = 0; i < n; i++){
			scanf("%d", &arr[i]);
		}
		if(n == 1 || n == 2){
			printf("0\n");
			continue;
		}
		sort(arr, arr+n);
		int j = 0;
		long long ans = 0;
		for(int i = 0; i < n; i++){
			if(j < i) j = i;
			while(j+1 < n && arr[j+1] - arr[i] <= 2) j++;
			if(j - i > 1){
				ans += (long long) (j-i-1)*(j-i)>>1;
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}