#include<bits/stdc++.h>
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define x first
#define y second
#define vi vector<int>
#define vpi vector<pii>
using namespace std;

inline void ckmin(int &a,int b){a=(a<b?a:b);}
inline void ckmax(int &a,int b){a=(a>b?a:b);}
inline int read()
{
	int f=1,num=0;char ch=getchar();
	while(!(ch=='-'||(ch<='9'&&ch>='0')))ch=getchar();
	if (ch=='-')f=-1,ch=getchar();
	while(ch<='9'&&ch>='0')num=num*10+ch-'0',ch=getchar();
	return num*f;
}

const int M=2.5e5+10;
int n,q,ans[M],a[M],b[M];
pii st1[M],st2[M];

struct segment_tree
{
	struct tree
	{
		int tl,tr;
		ull sa,sb,ta,tb,val;
	}t[M<<2];
	#define l(x) t[(x)].tl
	#define r(x) t[(x)].tr
	#define len(x) (r(x)-l(x)+1)
	#define sa(x) t[(x)].sa
	#define sb(x) t[(x)].sb
	#define ta(x) t[(x)].ta
	#define tb(x) t[(x)].tb
	#define val(x) t[(x)].val
	#define lson k<<1
	#define rson k<<1|1
	void adda(int k,ull z){sa(k)+=z*len(k),ta(k)+=z,val(k)+=z*sb(k);}
	void addb(int k,ull z){sb(k)+=z*len(k),tb(k)+=z,val(k)+=z*sa(k);}
	void pushdown(int k)
	{
		if (ta(k))adda(lson,ta(k)),adda(rson,ta(k)),ta(k)=0;
		if (tb(k))addb(lson,tb(k)),addb(rson,tb(k)),tb(k)=0;
	}
	void pushup(int k){val(k)=val(lson)+val(rson),sa(k)=sa(lson)+sa(rson),sb(k)=sb(lson)+sb(rson);}
	void build(int k,int l,int r)
	{
		l(k)=l,r(k)=r,val(k)=sa(k)=sb(k)=ta(k)=tb(k)=0;
		if (l==r)return;
		int Mid=(l+r)>>1;
		build(lson,l,Mid),build(rson,Mid+1,r);
	}
	void update(int k,int l,int r,int opt,ull z)
	{
		if (l(k)>=l&&r(k)<=r)
		{
			if (opt)adda(k,z);
			else addb(k,z);
			return;
		}
		if (l(k)>r||r(k)<l)return;
		pushdown(k);
		update(lson,l,r,opt,z),update(rson,l,r,opt,z);
		pushup(k);
	}
	ull query(){return val(1);}
}T;

/*struct fake
{
	ull a[M],b[M];
	void build(int k,int l,int r){}
	void update(int k,int l,int r,int opt,int z)
	{
		if (opt==1)for (int i=l;i<=r;i++)a[i]+=z;
		else for (int i=l;i<=r;i++)b[i]+=z;
	}
	int query()
	{
		ull res=0;
		for (int i=1;i<=n;i++)res+=a[i]*b[i];
		return res;
	}
}T;*/

signed main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	read(),n=read();
	for (int i=1;i<=n;i++)a[i]=read();
	for (int i=1;i<=n;i++)b[i]=read();
	q=read();int tp1=0,tp2=0;
	while(q--)
	{
		int l=read(),r=read();T.build(1,l,r);
		tp1=tp2=0;ull ans=0;
		for (int i=l;i<=r;i++)
		{
			T.update(1,i,i,1,a[i]);
			T.update(1,i,i,0,b[i]);
			while(tp1!=0&&a[i]>a[st1[tp1].y])
			{
				T.update(1,st1[tp1].x,st1[tp1].y,1,a[i]-a[st1[tp1].y]);
				tp1--;
			}
			tp1++;
			if (tp1==1)st1[tp1].x=l;
			else st1[tp1].x=st1[tp1-1].y+1;
			st1[tp1].y=i;
			while(tp2!=0&&b[i]>b[st2[tp2].y])
			{
				T.update(1,st2[tp2].x,st2[tp2].y,0,b[i]-b[st2[tp2].y]);
				tp2--;
			}
			tp2++;
			if (tp2==1)st2[tp2].x=l;
			else st2[tp2].x=st2[tp2-1].y+1;
			st2[tp2].y=i;
			ans+=T.query();
		}
		cout<<ans<<'\n';
	}
	return 0;
}
