#include<bits/stdc++.h>
#define int long long
#define maxn 250005
using namespace std;
int T,n,Q,a[2][maxn],h[maxn<<2][2];
inline int read(){
	int ret=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) ret=ret*10+ch-'0',ch=getchar();
	return ret;
}
inline void build(int L,int R,int p,int k){
	if(L==R){h[p][k]=a[k][L];return;}
	int mid=(L+R)>>1;
	build(L,mid,p<<1,k);build(mid+1,R,p<<1|1,k);
	h[p][k]=max(h[p<<1][k],h[p<<1|1][k]);
}
inline long long get(int L,int R,int p,int l,int r,int k){
	if(L>=l&&R<=r) return h[p][k];
	int mid=(L+R)>>1,ret=0;
	if(l<=mid) ret=max(ret,get(L,mid,p<<1,l,r,k));
	if(r>mid) ret=max(ret,get(mid+1,R,p<<1|1,l,r,k));
	return ret;
}
signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	T=read(),n=read();
	for(int i=1;i<=n;i++) a[0][i]=read();build(1,n,1,0);
	for(int i=1;i<=n;i++) a[1][i]=read();build(1,n,1,1);
	Q=read();
	while(Q--){
		int l=read(),r=read(),ans=0;
		for(int i=l;i<=r;i++)
		for(int j=i;j<=r;j++) ans+=get(1,n,1,i,j,1)*get(1,n,1,i,j,0);
		printf("%lld\n",ans);
	}
	return 0;
}