#include<bits/stdc++.h>
#define rr register
#define maxn 250005
#define TT 18446744073709551616
#define ull unsigned long long
using namespace std;
inline int read(){
	rr int num=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9') num=(num<<3)+(num<<1)+ch-'0',ch=getchar();
	return f*num;
}
struct dd{
	int l,r;
	int a,b;
	#define l(x) t[x].l
	#define r(x) t[x].r
	#define a(x) t[x].a
	#define b(x) t[x].b
}t[4*maxn];
int T,n,Q;
int a[maxn],b[maxn];
int ans;
void build(int p,int l,int r){
	l(p)=l,r(p)=r;
	if(l==r){
		a(p)=a[l],b(p)=b[l];
		return ;
	}
	rr int mid=l+r>>1;
	build(p*2,l,mid);
	build(p*2+1,mid+1,r);
	a(p)=max(a(p*2),a(p*2+1));
	b(p)=max(b(p*2),b(p*2+1));
}
inline int aska(int p,int l,int r){
	if(l(p)==r(p)) return a(p);
	rr int mid=l(p)+r(p)>>1,val=-1;
	if(l<=mid) val=max(val,aska(p*2,l,r));
	if(r>mid) val=max(val,aska(p*2+1,l,r));
	return val;
}
inline int askb(int p,int l,int r){
	if(l(p)==r(p)) return b(p);
	rr int mid=l(p)+r(p)>>1,val=-1;
	if(l<=mid) val=max(val,askb(p*2,l,r));
	if(r>mid) val=max(val,askb(p*2+1,l,r));
	return val;
}
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	T=read(),n=read();
	for(rr int i=1;i<=n;i++) a[i]=read();
	for(rr int i=1;i<=n;i++) b[i]=read();
	build(1,1,n);
//	for(rr int i=1;i<=n;i++) printf("%d %d\n",a[i],b[i]);
	Q=read();
	while(Q--){
		ans=0;
		rr int l=read(),r=read();
		for(rr int i=l;i<=r;i++)
		for(rr int j=i;j<=r;j++){
//			printf("%d %d %d %d\n",i,j,aska(1,i,j),askb(1,i,j));
			ans=(ans+aska(1,i,j)*askb(1,i,j));
		}
		printf("%d\n",ans);
	}
	return 0;
}
