#include<bits/stdc++.h>
using namespace std;
int a[10005],b[10005],mal[10005],mar[10005],mbl[10005],mbr[10005];
unsigned long long ans;
int T,n,p,l,r;
struct node{
	int id,x;
};
stack<node> q;
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>T>>n;
	for(register int i=1;i<=n;i++) cin>>a[i];
	for(register int i=1;i<=n;i++) cin>>b[i];
	a[n+1]=a[0]=b[n+1]=b[0]=2147483647;
	for(register int i=1;i<=n+1;i++)
	{
		while(!q.empty()&&q.top().x<a[i]) 
		{
			int now=q.top().id;
			mar[now]=i-1;
			q.pop();
		}
		node t;
		t.x=a[i];
		t.id=i;
		q.push(t);
	}
	while(!q.empty())  q.pop();
	for(register int i=n;i>=0;i--)
	{
		while(!q.empty()&&q.top().x<a[i])
		{
			int now=q.top().id;
			mal[now]=i+1;
			q.pop();
		}
		node t;
		t.x=a[i],t.id=i;
		q.push(t);
	}
	while(!q.empty())  q.pop();
	for(register int i=1;i<=n+1;i++)
	{
		while(!q.empty()&&q.top().x<b[i]) 
		{
			int now=q.top().id;
			mbr[now]=i-1;
			q.pop();
		}
		node t;
		t.x=b[i];
		t.id=i;
		q.push(t);
	}
	while(!q.empty())  q.pop();
	for(register int i=n;i>=0;i--)
	{
		while(!q.empty()&&q.top().x<b[i])
		{
			int now=q.top().id;
			mbl[now]=i+1;
			q.pop();
		}
		node t;
		t.x=b[i],t.id=i;
		q.push(t);
	}
	cin>>p;
	while(p--)
	{
		ans=0;
		cin>>l>>r;
		for(register int i=l;i<=r;i++)
		{
			for(register int j=i;j<=r;j++)
			{
				if(mar[i]>=j&&mbl[j]<=i) 
				ans+=1ll*a[i]*b[j]*(min(r,(mar[i]<mbr[j]?mar[i]:mbr[j]))-j+1)*(i-max(l,max(mbl[j],mal[i]))+1);
				if(mbr[i]>=j&&mal[j]<=i)
				ans+=1ll*b[i]*a[j]*(min(r,(mar[j]<mbr[i]?mar[j]:mbr[i]))-j+1)*(i-max(l,max(mbl[i],mal[j]))+1);
			}
			ans-=1ll*b[i]*a[i]*(min(r,(mar[i]<mbr[i]?mar[i]:mbr[i]))-i+1)*(i-max(l,max(mbl[i],mal[i]))+1);
		}
		cout<<ans<<endl;
	}
	return 0;
}
