#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,k,fa[20][N],q,i,l[N],r[N],x[N],j;
long long ans[N],faf[20][N];
int main()
{
	scanf("%d %d",&n,&k);
	for(i=1;i<=n;++i)
		scanf("%d",&x[i]);
	scanf("%d",&q);
	for(i=1;i<=q;++i)
		scanf("%d %d",&l[i],&r[i]);
	x[0]=-k-1;
	x[n+1]=x[n]+k+1;
	for(i=n;i>=1;--i)
	{
		fa[0][i]=upper_bound(x+1,x+1+n,x[i]-k)-x-1;
		faf[0][i]=i;
	}
	for(i=1;i<20;++i)
		for(j=1;j<=n;++j)
		{
			fa[i][j]=fa[i-1][fa[i-1][j]];
			faf[i][j]=faf[i-1][j]+faf[i-1][fa[i-1][j]];
		}
	for(i=1;i<=q;++i)
	{
		int p=r[i];
		for(j=19;j>=0;--j)
			if(fa[j][p]>=l[i])
			{
				ans[i]+=faf[j][p];
				p=fa[j][p];
			}
		ans[i]+=faf[0][p];
	}

	for(i=1;i<=n;++i)
	{
		fa[0][i]=lower_bound(x+1,x+2+n,x[i]+k)-x;
		faf[0][i]=i-1;
	}
	fa[0][n+1]=n+1;
	for(i=1;i<20;++i)
		for(j=1;j<=n+1;++j)
		{
			fa[i][j]=fa[i-1][fa[i-1][j]];
			faf[i][j]=faf[i-1][j]+faf[i-1][fa[i-1][j]];
		}
	for(i=1;i<=q;++i)
	{
		int p=l[i];
		for(j=19;j>=0;--j)
			if(fa[j][p]<=r[i])
			{
				ans[i]-=faf[j][p];
				p=fa[j][p];
			}
		ans[i]-=faf[0][p];
	}
	for(i=1;i<=q;++i)
		printf("%lld\n",ans[i]);
}
