#include<bits/stdc++.h>
using namespace std;
#define mid (l+r>>1)
typedef long long ll;
inline int read(){
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=(x<<3)+(x<<1)+(c^48);
	return x*f;
}
int tra[400005],trb[400005];
int id,n,q;
inline void pushup(int root,int tr[]){
	tr[root]=max(tr[root<<1],tr[root<<1|1]);
	return;
}
void build(int root,int l,int r,int tr[]){
	if(l==r){
		tr[root]=read();
		return;
	}
	build(root<<1,l,mid,tr),build(root<<1|1,mid+1,r,tr);
	pushup(root,tr);
	return;
}
int query(int root,int l,int r,int x,int y,int tr[]){
	if(l>=x&&r<=y){
		return tr[root];
	}
	int ans=0;
	if(mid>=x)ans=max(query(root<<1,l,mid,x,y,tr),ans);
	if(mid<y)ans=max(query(root<<1|1,mid+1,r,x,y,tr),ans);
	return ans;
}
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	id=read(),n=read();
	build(1,1,n,tra),build(1,1,n,trb);
	q=read();
	while(q--){
		int l=read(),r=read();
		ll ans=0;
		for(int i=l;i<=r;i++){
			for(int j=i;j<=r;j++){
				ans+=(ll)query(1,1,n,i,j,tra)*query(1,1,n,i,j,trb);
			}
		}
		printf("%lld\n",ans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
