//
// Created by yamunaku on 2020/09/20.
//

#include <bits/stdc++.h>
//#include <atcoder/all>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main() {
    //CFS;
    int n, k;
    cin >> n >> k;
    vl a(n + 2);
    a[0] = -LINF, a[n + 1] = LINF;
    repl(i, 1, n + 1) cin >> a[i];
    int lg = 0;
    int tmp = 1;
    while (tmp < n + 2) tmp *= 2, lg++;
    mti fl(lg, vi(n + 2)), fr(lg, vi(n + 2));
    mtl sl(lg, vl(n + 2)), sr(lg, vl(n + 2));
    fl[0][0] = fr[0][0] = 0;
    fl[0][n + 1] = fr[0][n + 1] = n + 1;
    sl[0][0] = sr[0][0] = 0;
    sl[0][n + 1] = sr[0][n + 1] = 0;
    repl(i, 1, n + 1) {
        fl[0][i] = lower_bound(all(a), a[i] + k) - a.begin();
        fr[0][i] = upper_bound(all(a), a[i] - k) - a.begin() - 1;
        sl[0][i] = i;
        sr[0][i] = i + 1;
    }
    repl(t, 1, lg) {
        fl[t][0] = fr[t][0] = 0;
        fl[t][n + 1] = fr[t][n + 1] = n + 1;
        sl[t][0] = sr[t][0] = 0;
        sl[t][n + 1] = sr[t][n + 1] = 0;
        repl(i, 1, n + 1) {
            fl[t][i] = fl[t - 1][fl[t - 1][i]];
            fr[t][i] = fr[t - 1][fr[t - 1][i]];
            sl[t][i] = sl[t - 1][i] + sl[t - 1][fl[t - 1][i]];
            sr[t][i] = sr[t - 1][i] + sr[t - 1][fr[t - 1][i]];
        }
    }
    int q;
    cin >> q;
    rep(t, q) {
        int l, r;
        cin >> l >> r;
        int tl = l, tr = r;
        ll sum = 0;
        per(i, lg) {
            if (fl[i][tl] <= r) {
                sum -= sl[i][tl];
                tl = fl[i][tl];
            }
            if (fr[i][tr] >= l) {
                sum += sr[i][tr];
                tr = fr[i][tr];
            }
        }
        sum -= tl;
        sum += tr+1;
        cout << sum << endl;
    }
    return 0;
}
