#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
const int M = 1000000007;
const int N = 3e5+9;
const int INF = 2e9+1;
const int MAXN = 100000;
const int LINF = 2000000000000000001;
//_ ***************************** START Below *******************************
vector<int> a;
//* Template1 for Atmost k (i.e. <= k )
void consistency1(int n, int k){
deque<int> up, down; //* indices
int s = 0, e = 0;
int ans = 0;
while(e<n){
//* Calculate state => invalidate dq
while(!down.empty() && a[e] > a[down.back()] ){
down.pop_back();
}
down.push_back(e);
while(!up.empty() && a[e] < a[up.back()]){
up.pop_back();
}
up.push_back(e);
//* Valid window => expand + Compute result
int mini = a[up.front()];
int maxi = a[down.front()];
int diff = maxi - mini;
if(diff * (e-s+1) <= k){
ans += (e-s+1);
e++;
}
else{
//* Invlaid window => Shrink
while(s<e){
int maxi = a[down.front()];
int mini = a[up.front()];
int diff = maxi - mini;
if(diff * (e-s+1) <= k) break;
if(up.front() == s) up.pop_front();
if(down.front() == s) down.pop_front();
s++;
}
//* valid window => Compute result
ans += (e-s+1);
e++;
}
}
cout << ans << endl;
}
//* Template2 for Atmost k (i.e. <= k )
//* (based on Cache Invalidation)
void consistency2(int n, int k){
deque<int> up, down; //* indices
int ans = 0;
int s=0, e=0;
while(e<n){
//* Calculate State => Invalidate dq
while(!down.empty() && a[e] > a[down.back()] ){
down.pop_back();
}
down.push_back(e);
while(!up.empty() && a[e] < a[up.back()]){
up.pop_back();
}
up.push_back(e);
//* Invalid window => shrink
while(s<e){
int maxi = a[down.front()];
int mini = a[up.front()];
int diff = maxi - mini;
if(diff * (e-s+1) <= k) break;
if(up.front() == s) up.pop_front();
if(down.front() == s) down.pop_front();
s++;
}
//* Valid window Guranteed => Compute Result
int mini = a[up.front()];
int maxi = a[down.front()];
int diff = maxi - mini;
ans += (e-s+1);
e++;
}
cout << ans << endl;
}
void solve() {
int n, k;
cin >> n >> k;
a.resize(n);
for(int i=0; i<n; i++) cin >> a[i];
consistency1(n, k);
consistency2(n, k);
cout << endl;
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}