#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define par pair<int,int>
#define pb push_back
#define mkp make_pair
using namespace std;
const int M=2e5+5e4+5;
ll RD(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
	return x*f;
}
int id,n,m,siz;
struct que{int l,r,id,L;}q[M];ll Ans[M];
ll a[M],b[M];int l,r;
ll ans;
void Add(int x,int t){
	if(t)
	{
		ll ma=0,mb=0;
		for(int i=x;i<=r;i++)
		{
			ma=max(ma,a[i]),mb=max(mb,b[i]);
			ans+=ma*mb;
		}
	}
	else
	{
		ll ma=0,mb=0;
		for(int i=x;i>=l;i--)
		{
			ma=max(ma,a[i]),mb=max(mb,b[i]);
			ans+=ma*mb;
		}
	}
}
void sub1(){
	for(int i=1,pre=-1;i<=m;i++)
	{
		if((q[i].r-1)/siz+1==q[i].L)
		{
			for(int j=q[i].l;j<=q[i].r;j++)
			{
				ll ma=0,mb=0;
				for(int w=j;w<=q[i].r;w++)
				{
					ma=max(ma,a[w]),mb=max(mb,b[w]);
					Ans[q[i].id]+=ma*mb;
				}
			}continue;
		}
		if(q[i].L^pre)
		{
			ans=0;
			l=q[i].L*siz,r=l-1;
			pre=q[i].L;
		}
		while(r<q[i].r)Add(++r,0);
		int tl=l;ll tmp=ans;
		while(l>q[i].l)Add(--l,1);
		Ans[q[i].id]=ans;
		ans=tmp,l=tl;
	}
	for(int i=1;i<=m;i++)printf("%lld\n",Ans[i]);
}
int main(){
	
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	
	id=RD(),n=RD();siz=sqrt(n);
	for(int i=1;i<=n;i++)a[i]=RD();
	for(int i=1;i<=n;i++)b[i]=RD();
	m=RD();
	for(int i=1;i<=m;i++)q[i].l=RD(),q[i].r=RD(),q[i].id=i,q[i].L=(q[i].l-1)/siz+1;
	sort(q+1,q+1+m,[](que&a,que&b){return(a.L^b.L)?a.L<b.L:a.r<b.r;});
	sub1();
	return 0;
}