#include<bits/stdc++.h>
#define ll unsigned long long

using namespace std;
int debug=0;
const int N=2.5e5+10;
struct Tr{
	ll tr[N];
	int xx[N];
	inline int ls(int x)
	{
		return x<<1;
	}
	inline int rs(int x)
	{
		return x<<1|1;
	}
	void up(int x)
	{
		tr[x]=max(tr[ls(x)],tr[rs(x)]);
		
	}
	int build(int x,int l,int r)
	{
		if(l==r)
		{
			tr[x]=xx[l];
			return 0;
		}
		int mid=(l+r)>>1;
		build(ls(x),l,mid);
		build(rs(x),mid+1,r);
		up(x);
		return 0;
	}
	ll get(int x,int l,int r,int nl,int nr)
	{
		if(nl<=l&&r<=nr) return tr[x];
		else if(nr<l||nl>r) return 0;
		ll mx=0;
		int mid=(l+r)>>1;
		mx=max(mx,get(ls(x),l,mid,nl,nr));
		mx=max(mx,get(rs(x),mid+1,r,nl,nr));
		return mx;
	}
}a,b;
int lg[N];
ll sum;
int t,n,q;
//ll mx(int l,int r)
//{
//	if(debug) printf("%d %d ",l,r);
//	if(debug) printf("%lld ",max(sta[lg[r-l+1]][l],sta[lg[r-l+1]][r-1<<lg[r-l+1]+1]));
//	if(debug) printf("%lld\n",max(stb[lg[r-l+1]][l],stb[lg[r-l+1]][r-1<<lg[r-l+1]+1]));
//	return 1ull*max(sta[lg[r-l+1]][l],sta[lg[r-l]][r-1<<lg[r-l+1]+1])*
//			max(stb[lg[r-l+1]][l],stb[lg[r-l]][r-1<<lg[r-l+1]+1]);
//}
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%d%d",&t,&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a.xx[i]);

	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&b.xx[i]);
	}
	a.build(1,1,n);
	b.build(1,1,n);
	scanf("%d",&q);
	while(q--)
	{
		sum=0;
		int l,r;
		scanf("%d%d",&l,&r);
		for(int i=l;i<=r;i++)
		{
			for(int j=i;j<=r;j++)
			{
				sum=(sum+a.get(1,1,n,i,j)*b.get(1,1,n,i,j));
			}
		}
		printf("%llu\n",sum);
	}
	



	return 0;
}
