#include <bits/stdc++.h>
using namespace std;
 
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL); cout.tie(NULL);}
#define f first
#define s second
#define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
typedef long long ll;
typedef long double lld;
typedef unsigned long long ull;
 
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
	cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
	cin >> p.first;
	return cin >> p.second;
}
 
mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(61378913);
/* usage - just do rng() */
 
void usaco(string filename) {
  // #pragma message("be careful, freopen may be wrong")
	freopen((filename + ".in").c_str(), "r", stdin);
	freopen((filename + ".out").c_str(), "w", stdout);
}

#include <atcoder/all>
using namespace atcoder;
 
const lld pi = 3.14159265358979323846;
// const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;
 
struct lca_lift {
  const int lg = 24;
  int n;
  vector<int> depth;
  vector<vector<int> > edges;
  vector<vector<int> > lift;
  vector<vector<ll> > sum;
  
  void init(int sz) {
    n = sz;
    depth = vector<int>(n);
    edges = vector<vector<int> >(n, vector<int>());
    sum = vector<vector<ll> >(n, vector<ll>(lg, 0));
    lift = vector<vector<int> >(n, vector<int>(lg, -1));
  }

  void edge(int a, int b) {
    edges[a].push_back(b);
    edges[b].push_back(a);
  }

  void init_lift(int v = 0) {
    depth[v] = 0;
    dfs(v, -1);
  }

  void dfs(int v, int par) {
    lift[v][0] = par;
	sum[v][0] = v;

    for (int i = 1; i < lg; i++) {
      if (lift[v][i - 1] == -1) {
		  lift[v][i] = -1;
		  sum[v][i] = 0;
	  } else {
		  lift[v][i] = lift[lift[v][i - 1]][i - 1];
		  sum[v][i] = sum[v][i - 1] + sum[lift[v][i - 1]][i - 1];
	  }
    }

    for (int x: edges[v]) {
      if (x != par) {
        depth[x] = depth[v] + 1;
        dfs(x, v);
      }
    }
  }

  int get_min(int v, int r) {
	int d = 0;
    for (int i = lg - 1; i >= 0; i--) {
      if (lift[v][i] != -1 && lift[v][i] <= r) {
        v = lift[v][i];
        d += (1 << i);
      }
    }
    return d;
  }
  
  ll get_sum(int v, int k) {
	ll s = 0;
	// cout << sum << '\n';
    for (int i = lg - 1; i >= 0; i--) {
		// cout << v << " " << i << " " << s << " " << k << " " << lift[v][i] << " " << sum[v][i] << endl;
      if ((1 << i) <= k) {
		  // cout << "WHAT " << v << " " << i << " " << s << " " << k << " " << lift[v][i] << " " << sum[v][i] << endl;
		s += sum[v][i];
        v = lift[v][i];
        k -= (1 << i);
		// cout << "WHAT " << v << " " << i << " " << s << " " << k << " " << lift[v][i] << " " << sum[v][i] << endl;
      }
    }
    return s;
  }
};

ll n, m, k, q, l, r, x, y, z;
const ll template_array_size = 1e6 + 1531;
ll a[template_array_size];
ll b[template_array_size];
ll c[template_array_size];
string s, t;
ll ans = 0;

ll par[200005];
lca_lift le, ri; // le - to the left, edges going right

void solve(int tc = 0) {
	cin >> n >> k;
	
	for (ll i = 0; i < n; i++) cin >> a[i];
	
	le.init(n);
	ri.init(n);
	
	for (ll i = 0; i < n; i++) par[i] = -1;
	
	ll lpt = 0;
	for (ll i = 0; i < n; i++) {
		while (lpt < n && a[lpt] - a[i] < k) ++lpt;
		
		if (lpt < n) {
			par[i] = lpt;
			le.edge(i, lpt);
		}
	}
	
	for (ll i = 0; i < n; i++) {
		if (par[i] == -1) {
			le.init_lift(i);
		}
	}
	
	for (ll i = 0; i < n; i++) par[i] = -1;
	
	ll rpt = n - 1;
	for (ll i = n - 1; i >= 0; i--) {
		while (rpt >= 0 && a[i] - a[rpt] < k) --rpt;
		
		if (rpt >= 0) {
			par[i] = rpt;
			ri.edge(i, rpt);
			// cout << i << " " << rpt << '\n';
		}
	}
	
	for (ll i = 0; i < n; i++) {
		if (par[i] == -1) {
			ri.init_lift(i);
		}
	}
	
	cin >> q;
	
	for (ll i = 0; i < q; i++) {
		cin >> l >> r;
		--l; --r;
		
		ll d = le.get_min(l, r) + 1;
				
		ll s1 = le.get_sum(l, d);
		ll s2 = ri.get_sum(r, d);
		
		// cout << d << " " << s1 << " " << s2 << '\n';
		
		cout << s2 - s1 + d << '\n';
	}
}
 
int main() {
	#ifdef galen_colin_local
		auto begin = std::chrono::high_resolution_clock::now();
	#endif
	
	send help
 
	#ifndef galen_colin_local
		// usaco("moop");
	#endif
	
	// usaco("cowland");
	
	// freopen("tc.cpp", "r", stdin);
 
	
	
	int tc = 1;
	// cin >> tc;
	for (int t = 0; t < tc; t++) solve(t);
	
	#ifdef galen_colin_local
		auto end = std::chrono::high_resolution_clock::now();
		cout << setprecision(4) << fixed;
		// cout << "Execution time: " << std::chrono::duration_cast<std::chrono::duration<double>>(end - begin).count() << " seconds" << endl;
	#endif
} 

Measured memory_bytes: 186076