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

// DEBUG BEGIN
#ifdef LOCAL
template<typename L, typename R> ostream &operator<<(ostream &out, const pair<L, R> &p){
	return out << "(" << p.first << ", " << p.second << ")";
}
template<typename Tuple, size_t N> struct TuplePrinter{
	static ostream &print(ostream &out, const Tuple &t){ return TuplePrinter<Tuple, N-1>::print(out, t) << ", " << get<N-1>(t); }
};
template<typename Tuple> struct TuplePrinter<Tuple, 1>{
	static ostream &print(ostream &out, const Tuple& t){ return out << get<0>(t); }
};
template<typename... Args> ostream &print_tuple(ostream &out, const tuple<Args...> &t){
	return TuplePrinter<decltype(t), sizeof...(Args)>::print(out << "(", t) << ")";
}
template<typename ...Args> ostream &operator<<(ostream &out, const tuple<Args...> &t){
	return print_tuple(out, t);
}
template<typename T> ostream &operator<<(enable_if_t<!is_same<T, string>::value, ostream> &out, const T &arr){
	out << "{"; for(auto &x: arr) out << x << ", ";
	return out << (arr.size() ? "\b\b" : "") << "}";
}
template<size_t S> ostream &operator<<(ostream &out, const bitset<S> &b){
	for(int i = 0; i < S; ++ i) out << b[i];
	return out;
}
void debug_out(){ cerr << "\b\b " << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){ cerr << H << ", ", debug_out(T...); }
void debug2_out(){ cerr << "-----DEBUG END-----\n"; }
template<typename Head, typename... Tail>
void debug2_out(Head H, Tail... T){ cerr << "\n"; for(auto x: H) cerr << x << "\n"; debug2_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#define debug2(...) cerr << "----DEBUG BEGIN----\n[" << #__VA_ARGS__ << "]:", debug2_out(__VA_ARGS__)
#else
#define debug(...) 42
#define debug2(...) 42
#endif
// DEBUG END

int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for(auto i = 0; i < n; ++ i){
		cin >> a[i];
	}
	vector next(__lg(n) + 1, vector(n, pair{numeric_limits<int>::max(), 0LL}));
	vector prev(__lg(n) + 1, vector(n, pair{numeric_limits<int>::min(), 0LL}));
	for(auto u = 0, v = 0; u < n; ++ u){
		while(v < n && a[v] < a[u] + k){
			++ v;
		}
		if(v < n){
			next[0][u] = {v, u + v};
		}
	}
	for(auto u = n - 1, v = n - 1; u >= 0; -- u){
		while(v >= 0 && a[v] > a[u] - k){
			-- v;
		}
		if(v >= 0){
			prev[0][u] = {v, u + v};
		}
	}
	for(auto bit = 1; bit <= __lg(n); ++ bit){
		for(auto u = 0; u < n; ++ u){
			int v = next[bit - 1][u].first;
			if(v < n){
				next[bit][u] = {next[bit - 1][v].first, next[bit - 1][u].second + next[bit - 1][v].second - v};
			}
			v = prev[bit - 1][u].first;
			if(v >= 0){
				prev[bit][u] = {prev[bit - 1][v].first, prev[bit - 1][u].second + prev[bit - 1][v].second - v};
			}
		}
	}
	debug2(next);
	debug2(prev);
	int qn;
	cin >> qn;
	for(auto qi = 0; qi < qn; ++ qi){
		int ul, ur;
		cin >> ul >> ur, -- ul, -- ur;
		int rmax = ur, sz = 1;
		long long rsum = ul, lsum = ur;
		for(int bit = __lg(n); bit >= 0; -- bit){
			if(next[bit][ul].first <= rmax){
				sz += 1 << bit;
				rsum += next[bit][ul].second - ul;
				ul = next[bit][ul].first;
				lsum += prev[bit][ur].second - ur;
				ur = prev[bit][ur].first;
			}
		}
		debug(lsum, rsum, sz);
		cout << lsum - rsum + sz << "\n";
	}
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 119592