//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9; 
const int N = 6e5+5;                                         
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}

int ans[N];
int d[N];
int same[N];
int from[N];
int x[N];
int parCnt[N];
int n, k;
struct BinLift {
	int up[18][N];
	ll sum[18][N];
	int f(int x, int lim) {
		int res = 1;
		for (int i = 17; ~i; --i) {
			//cout << up[i][x] << ' ' << x << '\n';
			if(up[i][x] > lim && x > lim) {
				x = up[i][x];
				res += (1<<i);
			}
		}
	
		return res;
	}
	
	ll get (int x, int k) {
		ll res = 0;
		for (int i = 17; ~i; --i) if(k&(1<<i))
			res += sum[i][x], x = up[i][x];
		return res;
	}

	int climb (int x, int k) {
		for (int i = 17; ~i; --i) if(k&(1<<i))
			x = up[i][x];
		return x;
	}
	void build() {
		for (int j = 1; j < 18; ++j) {
			for (int i = 1; i <= n; ++i) {
				int vv = up[j-1][i];
				if(vv == n+1) up[j][i] = n+1, sum[j][i] = sum[j][i-1];
				else {
					sum[j][i] = sum[j-1][i] + sum[j-1][vv];
					up[j][i] = up[j-1][vv];
				}
			}
		}
	}
} A, B;

int main () {
	SpeedForce;
	
	cin >> n >> k;
	int j = 0;
	from[0] = -1;
	for (int i = 1; i <= n; ++i) {
		cin >> x[i];
		while(x[i] - x[j+1] >= k) ++j;
		from[i] = j;
		d[i] = d[j] + 1;
		ans[i] = ans[j] + same[j];
		if(d[i] == d[i-1]) same[i] = same[i-1];
		++same[i];
		if(from[i] == from[i-1])
			parCnt[i] = parCnt[i-1];
		++parCnt[i];
		A.sum[0][i] = i;
		A.up[0][i] = j;
	}
	
	j = n+1;
	
	for (int i = n; i >= 1; --i) {
		while(x[j-1] - x[i] >= k) --j;
		B.up[0][i] = j;
		B.sum[0][i] = i;
	}
	
	A.build();
	B.build();
	
	int q;
	cin >> q;
	
	for (int i = 1; i <= q; ++i) {
		int l, r;
		cin >> l >> r;
		int now = A.f(r, l-1);
		//cout << now << ' ';
		//cout << A.get(r, now) << ' ' << B.get(l, now) << '\n';
		int res = A.get(r, now)-B.get(l, now) + now;
		
		cout << res << '\n';
	}
	
	return Accepted;
}

// B...a


Measured memory_bytes: 93080