#include <bits/stdc++.h>

#include <atcoder/all>

using namespace std;
using namespace atcoder;

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

const int L = 20;
const int maxn = 200010;

int nxtl[L][maxn], nxtr[L][maxn];
ll suml[L][maxn], sumr[L][maxn];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;
    V<int> X(N);
    rep(i, N) cin >> X[i];

    memset(nxtr, -1, sizeof(nxtr));

    int p = 0, q = 0;

    rep(i, N) {
        chmax(p, i);

        while (p < N && X[p] < X[i] + K) ++p;
        while (q < i && X[q + 1] <= X[i] - K) ++q;
        if (p < N) {
            nxtr[0][i] = p;
            sumr[0][i] = p;
        }
        if (X[q] - X[i] <= K) {
            nxtl[0][i] = q;
            suml[0][i] = q;
        }
    }

    rep(i, L - 1) {
        rep(j, N) {
            if (nxtr[i][j] == -1) {
                nxtr[i + 1][j] = -1;
            } else {
                nxtr[i + 1][j] = nxtr[i][nxtr[i][j]];
                sumr[i + 1][j] = sumr[i][j] + sumr[i][nxtr[i][j]];
            }
            if (nxtl[i][j] == -1) {
                nxtl[i + 1][j] = -1;
            } else {
                nxtl[i + 1][j] = nxtl[i][nxtl[i][j]];
                suml[i + 1][j] = suml[i][j] + suml[i][nxtl[i][j]];
            }
        }
    }

    int Q;
    cin >> Q;

    rep(i, Q) {
        int l, r;
        cin >> l >> r;
        --l, --r;
        int p = l, q = r;
        ll sr = l, sl = r;
        int cnt = 0;
        per(j, L) {
            if (nxtr[j][p] != -1 && nxtr[j][p] <= r) {
                sr += sumr[j][p];
                p = nxtr[j][p];
                sl += suml[j][q];
                q = nxtl[j][q];
                cnt |= 1 << j;
            }
        }
        cnt++;
        cout << sl - sr + cnt << '\n';
    }

    return 0;
}

Measured memory_bytes: 94148