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

#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) {
    return uniform_int_distribution<int>(l, r) (rng);
}

const int N = 2e5+100;
const int LOG = 20;

int a[N];
int nxt[N][LOG], prv[N][LOG];
long long nxt_sum[N][LOG], prv_sum[N][LOG];

int main() {
//    freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, K;
    cin >> n >> K;
    for(int i = 1; i <= n; i++) cin >> a[i];

    for(int i = 1; i <= n; i++) {
        if(a[n]-a[i] < K) nxt[i][0] = -1;
        else {
            int lo = i+1, hi = n;
            while(hi > lo) {
                int mid = lo+hi>>1;
                if(a[mid]-a[i] >= K) hi = mid;
                else lo = mid+1;
            }
            nxt[i][0] = lo;
        }
        nxt_sum[i][0] = i;
    }
    for(int i = 1; i <= n; i++) {
        if(a[i]-a[1] < K) prv[i][0] = -1;
        else {
            int lo = 1, hi = i-1;
            while(hi > lo) {
                int mid = (lo+hi+1)>>1;
                if(a[i]-a[mid] >= K) lo = mid;
                else hi = mid-1;
            }
            prv[i][0] = lo;
        }
        prv_sum[i][0] = i;
    }

    for(int k = 1; k < LOG; k++) {
        for(int i = 1; i <= n; i++) {
            if(nxt[i][k-1] == -1) nxt[i][k] = -1;
            else {
                nxt[i][k] = nxt[nxt[i][k-1]][k-1];
                nxt_sum[i][k] = nxt_sum[i][k-1] + nxt_sum[nxt[i][k-1]][k-1];
            }

            if(prv[i][k-1] == -1) prv[i][k] = -1;
            else {
                prv[i][k] = prv[prv[i][k-1]][k-1];
                prv_sum[i][k] = prv_sum[i][k-1] + prv_sum[prv[i][k-1]][k-1];
            }
        }
    }
    int q;
    cin >> q;
    while(q--) {
        int l, r;
        cin >> l >> r;
        int m = 1;
        int cur = l;
        for(int k = LOG-1; k >= 0; k--) {
            if(nxt[cur][k] != -1 && nxt[cur][k] <= r) {
                cur = nxt[cur][k];
                m += (1<<k);
            }
        }
        int curl = l, curr = r;
        long long lsum = 0, rsum = 0;
        for(int k = LOG-1; k >= 0; k--) {
            if((m >> k) & 1) {
                lsum += nxt_sum[curl][k];
                rsum += prv_sum[curr][k];
                curl = nxt[curl][k];
                curr = prv[curr][k];
            }
        }
        long long ans = rsum - lsum + m;
        cout << ans << "\n";
    }
}



