using System;
using System.Linq;
using CompLib.Util;
using System.Threading;
using System.Collections.Generic;

public class Program
{
    int N, K;
    int[] X;

    // iから2^j個後ろ
    List<int>[] Next, Prev;

    // iから2^j個後ろまでの和(半開区間)
    List<long>[] FSum, BSum;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        K = sc.NextInt();
        X = sc.IntArray();

        Next = new List<int>[N];
        FSum = new List<long>[N];
        for (int i = N - 1; i >= 0; i--)
        {
            int ok = N;
            int ng = i;
            while (ok - ng > 1)
            {
                int mid = (ok + ng) / 2;
                if (X[i] + K <= X[mid]) ok = mid;
                else ng = mid;
            }
            Next[i] = new List<int>();
            FSum[i] = new List<long>();
            Next[i].Add(ok);
            FSum[i].Add(i);
            int p = 0;
            while (Next[i][p] < N && p < Next[Next[i][p]].Count)
            {
                Next[i].Add(Next[Next[i][p]][p]);
                FSum[i].Add(FSum[i][p] + FSum[Next[i][p]][p]);
                p++;
            }
        }

        Prev = new List<int>[N];
        BSum = new List<long>[N];
        for (int i = 0; i < N; i++)
        {
            int ok = -1;
            int ng = i;
            while (ng - ok > 1)
            {
                int mid = (ok + ng) / 2;
                if (X[mid] + K <= X[i]) ok = mid;
                else ng = mid;
            }
            Prev[i] = new List<int>();
            BSum[i] = new List<long>();
            Prev[i].Add(ok);
            BSum[i].Add(i);
            int p = 0;
            while (Prev[i][p] >= 0 && p < Prev[Prev[i][p]].Count)
            {
                Prev[i].Add(Prev[Prev[i][p]][p]);
                BSum[i].Add(BSum[i][p] + BSum[Prev[i][p]][p]);
                p++;
            }
        }

        int q = sc.NextInt();
        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        for (int t = 0; t < q; t++)
        {
            int l = sc.NextInt() - 1;
            int r = sc.NextInt();

            long front = 0;
            int m = 0;
            int cur = l;
            while (Next[cur][0] < r)
            {
                for (int i = Next[cur].Count - 1; i >= 0; i--)
                {
                    if (Next[cur][i] < r)
                    {
                        m += 1 << i;
                        front += FSum[cur][i];
                        cur = Next[cur][i];
                        break;
                    }
                }
            }
            front += FSum[cur][0];
            m++;

            long back = 0;
            cur = r - 1;
            while (Prev[cur][0] >= l)
            {
                for (int i = Prev[cur].Count - 1; i >= 0; i--)
                {
                    if (Prev[cur][i] >= l)
                    {
                        back += BSum[cur][i];
                        cur = Prev[cur][i];
                        break;
                    }
                }
            }
            back += BSum[cur][0];


            // Console.WriteLine($"{front} {back}");
            Console.WriteLine(back - front + m);

        }

        Console.Out.Flush();

    }

    public static void Main(string[] args) => new Program().Solve();
    // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 329852