#include<bits/stdc++.h>
using namespace std;
const int N=3e5;
#define mid ((l+r)>>1)
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
int a1[N<<2],b1[N<<2];
int n,T,a[N],b[N];
long long ans=0;
inline void build1(int rt,int l,int r){
	if(l==r){
		a1[rt]=a[l];
		return ;
	}
	build1(lson);
	build1(rson);
	a1[rt]=max(a1[rt<<1],a1[rt<<1|1]);
}
inline int query1(int rt,int l,int r,int L,int R){
	int ans=0;
	if(L<=l&&R>=r){
		return ans=max(ans,a1[rt]);  
	}
	if(L<=mid) ans=max(ans,query1(lson,L,R));
	if(R>mid) ans=max(ans,query1(rson,L,R));
	return ans;
}
inline void build2(int rt,int l,int r){
	if(l==r){
		b1[rt]=b[l];
		return ;
	}
	build2(lson);
	build2(rson);
	b1[rt]=max(b1[rt<<1],b1[rt<<1|1]);
}
inline int query2(int rt,int l,int r,int L,int R){
	int ans=0;
	if(L<=l&&R>=r){
		return ans=max(ans,b1[rt]);  
	}
	if(mid>=L) ans=max(ans,query2(lson,L,R));
	if(R>mid) ans=max(ans,query2(rson,L,R));
	return ans;
}
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[i]);
	}
	build1(1,1,n);
	for(int j=1;j<=n;j++) scanf("%d",&b[j]);
	build2(1,1,n);
	int Q;
	scanf("%d",&Q);
	while(Q--){
		ans=0;
		int l,r;
		scanf("%d%d",&l,&r);
		for(int i=l;i<=r;i++){
			for(int j=i;j<=r;j++){
				ans+=(query1(1,1,n,i,j)*query2(1,1,n,i,j));
			}
		}
		printf("%lld\n",ans);
	}
}
