#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;

ll binary_search(
    ll lo, ll hi, function<bool(ll)> is_ok,
    bool maximize
){
    while(lo < hi){
        if(maximize){
            const ll mid = (lo + hi + 1) / 2;
            if(is_ok(mid)){
                lo = mid;
            }else{
                hi = mid - 1;
            }
        }else{
            ll mid = (lo + hi - 1) / 2;
            if(is_ok(mid)){
                hi = mid;
            }else{
                lo = mid + 1;
            }
        }
    }
    return lo;
}

template<typename S, S op(S, S)>
struct Doubling {
    vector<vector<S>> v;

    Doubling(const vector<S>& step1, ll p){
        const auto n = step1.size();
        v.resize(p);
        v.at(0) = step1;
        for(ll i = 1; i < p; ++i){
            v.at(i).resize(n);
            for(ll j = 0; j < n; ++j){
                const auto& x = v.at(i - 1).at(j);
                const auto& y = v.at(i - 1).at(x.index);
                v.at(i).at(j) = op(x, y);
            }
        }
    }

    S query(S init, ll nstep){
        S ret = init;
        REP(i, v.size()){
            if((nstep >> i) & 1){
                ret = op(ret, v.at(i).at(ret.index));
            }
        }
        return ret;
    }
};

struct S { ll index_sum, is_ok, index; };
S op(S x, S y){
    return S{
        x.index_sum + y.index_sum,
        y.is_ok,
        y.index
    };
}

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> x(n);
    REP(i, n){ cin >> x.at(i); }

    vector<S> l2r_1step(n), r2l_1step(n);
    REP(i, n){
        const auto xi = x.at(i);
        // to right
        ll ridx = lower_bound(ALL(x), xi + k) - x.begin();
        if(ridx >= x.size()){
            l2r_1step.at(i) = S{0, false, i};
        }else{
            l2r_1step.at(i) = S{ridx, true, ridx};
        }

        // to left
        ll lidx = upper_bound(ALL(x), xi - k) - x.begin();
        lidx--;
        if(lidx < 0){
            r2l_1step.at(i) = S{0, false, i};
        }else{
            r2l_1step.at(i) = S{lidx, true, lidx};
        }
    }

    Doubling<S, op> d_l2r(l2r_1step, 35), d_r2l(r2l_1step, 35);

    ll q;
    cin >> q;
    REP(i, q){
        ll l, r;
        cin >> l >> r;
        l--; r--;

        // cerr << "i=" << i << ", l=" << l << ", r=" << r << endl;

        const ll num = ::binary_search(
            0, n,
            [&](ll m) -> bool {
                const auto tmp = d_l2r.query(S{l, true, l}, m);
                return tmp.is_ok && x.at(tmp.index) <= x.at(r);
            },
            true
        );
        // cerr << "  num=" << num << endl;

        const S l2r = d_l2r.query(S{l, true, l}, num);
        const S r2l = d_r2l.query(S{r, true, r}, num);
        // cerr << "  l2r={" << l2r.index_sum << ", " << l2r.is_ok << ", " << l2r.index << "}" << endl;
        // cerr << "  r2l={" << r2l.index_sum << ", " << r2l.is_ok << ", " << r2l.index << "}" << endl;
        assert(l2r.is_ok && x.at(l2r.index) <= x.at(r));
        assert(r2l.is_ok && x.at(r2l.index) >= x.at(l));

        cout << r2l.index_sum - l2r.index_sum + num + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 342540