#include <bits/stdc++.h>
using namespace std;
int a[250010],b[250010],c[250010];
int tree1[2000010],tree2[2000010];
int n;
void build1(int l,int r,int x)
{
	if (l==r)
	{
		tree1[x]=a[l];
		return;
	}
	int mid=(l+r)>>1;
	build1(l,mid,x<<1);
	build1(mid+1,r,x<<1|1);
	tree1[x]=max(tree1[x<<1],tree1[x<<1|1]);
}
int query1(int ll,int rr,int l,int r,int x)
{
	if (ll<=l&&r<=rr) return tree1[x];
	int mid=(l+r)>>1,ans=0;
	if (ll<=mid) ans=max(ans,query1(ll,rr,l,mid,x<<1));
	if (rr>mid) ans=max(ans,query1(ll,rr,mid+1,r,x<<1|1));
	return ans;
}
void build2(int l,int r,int x)
{
	if (l==r)
	{
		tree2[x]=b[l];
		return;
	}
	int mid=(l+r)>>1;
	build2(l,mid,x<<1);
	build2(mid+1,r,x<<1|1);
	tree2[x]=max(tree2[x<<1],tree2[x<<1|1]);
}
int query2(int ll,int rr,int l,int r,int x)
{
	if (ll<=l&&r<=rr) return tree2[x];
	int mid=(l+r)>>1,ans=0;
	if (ll<=mid) ans=max(ans,query2(ll,rr,l,mid,x<<1));
	if (rr>mid) ans=max(ans,query2(ll,rr,mid+1,r,x<<1|1));
	return ans;
}
int main()
{
	freopen("match.in","r",stdin);freopen("match.out","w",stdout);
	int opt,t;
	scanf("%d%d",&opt,&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for (int i=1;i<=n;i++)
		scanf("%d",&b[i]);
	build1(1,n,1);
	build2(1,n,1);
	scanf("%d",&t);
	while (t--)
	{
		int l,r,m;
		unsigned long long sum1=0,sum2=0,s1,s2,ans=0;
		scanf("%d%d",&l,&r);
		for (int i=l;i<=r;i++)
			for (int j=i;j<=r;j++)
			{
				sum1=query1(i,j,1,n,1);
				sum2=query2(i,j,1,n,1);
				ans=ans+sum1*sum2;
			}
		cout<<ans<<endl;
	}
	return 0;
}