#include<bits/stdc++.h>
#define N 100005
#define int unsigned long long
using namespace std;
int T,n,Q,a[N],b[N],sa[N][21],sb[N][21],lg[N],s,th,ans[N];
inline int read(){
	int res=0;char ch=getchar();int f=ch=='-'?-1:1;
	while(ch<'0'||ch>'9')ch=getchar(),f=ch=='-'?-1:f;
	while(ch>='0'&&ch<='9')res=res*10+ch-'0',ch=getchar();
	return res*f;
}
struct p{
	int l,r,id;
}q[N];
inline void pre(){
	for(int i=1;i<=n;++i)lg[i]=lg[i-1]+(1<<lg[i-1]==i);
	for(int j=1;j<21;++j)
	for(int i=1;i+(1<<j)-1<=n;++i)
	sa[i][j]=max(sa[i][j-1],sa[i+(1<<j-1)][j-1]),
	sb[i][j]=max(sb[i][j-1],sb[i+(1<<j-1)][j-1]);
}
inline int rmq(int x,int y){
	int s=lg[y-x+1]-1;
	return max(sa[x][s],sa[y-(1<<s)+1][s])*max(sb[x][s],sb[y-(1<<s)+1][s]);
}
inline bool cmp(p x,p y){
	if(x.l/s!=y.l/s)return x.l/s<y.l/s;
	return x.r<y.r;
}
inline int v1(int l,int r){
	int res=0;
	for(int i=l;i<=r;++i)res+=rmq(l,i);
	return res;
}
inline int v2(int r,int l){
	int res=0;
	for(int i=r;i>=l;--i)res+=rmq(i,r);
	return res;
}
signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	T=read(),n=read();s=sqrt(n);
	for(int i=1;i<=n;++i)a[i]=read(),sa[i][0]=a[i];
	for(int i=1;i<=n;++i)b[i]=read(),sb[i][0]=b[i];
	pre();Q=read();
	for(int i=1;i<=Q;++i)q[i].l=read(),q[i].r=read(),q[i].id=i;
	sort(q+1,q+Q+1,cmp);
	int l=1,r=0;
	for(int i=1;i<=Q;++i){
		while(l>q[i].l)th+=v1(l-1,r),--l;
		while(l<q[i].l)th-=v1(l,r),++l;
		while(r<q[i].r)th+=v2(r+1,l),++r;
		while(r>q[i].r)th-=v2(r,l),--r;
		ans[q[i].id]=th;
	}
	for(int i=1;i<=Q;++i)printf("%lld\n",ans[i]);
	return 0;
}
