#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int M=3e5;
int T,Q,n,a[M],b[M];
ll ans;
struct Segmenttree{
	int l,r;
	ll maxn;
	#define l(p) tree1[p].l
	#define r(p) tree1[p].r
	#define ma(p) tree1[p].maxn
	#define ll(p) tree2[p].l
	#define rr(p) tree2[p].r
	#define mma(p) tree2[p].maxn
	#define p1 p<<1
	#define p2 p<<1|1
}tree1[M<<2],tree2[M<<2];
void build1(int p,int l,int r){
	l(p)=l;r(p)=r;
	if(l==r){
		ma(p)=a[l];
		return;
	}
	int mid=(l+r)/2;
	if(l<=mid) build1(p1,l,mid);
	if(r>mid) build1 (p2,mid+1,r);
	ma(p)=max(ma(p1),ma(p2));
}
void build2(int p,int l,int r){
	ll(p)=l;rr(p)=r;
	if(l==r){
		mma(p)=b[l];
		return;
	}
	int mid=(l+r)/2;
	if(l<=mid) build2(p1,l,mid);
	if(r>mid) build2 (p2,mid+1,r);
	mma(p)=max(mma(p1),mma(p2));
}
ll ask1(int p,int l,int r){
	if(l(p)>=l &&r(p)<=r) return ma(p);
	int mid=(l(p)+r(p))/2;
	ll val=0;
	if(l<=mid) val=max(val,ask1(p1,l,r));
	if(r>mid) val =max(val,ask1(p2,l,r));
	return val;
}
ll ask2(int p,int l,int r){
	if(ll(p)>=l &&rr(p)<=r) return mma(p);
	int mid=(ll(p)+rr(p))/2;
	ll val=0;
	if(l<=mid) val=max(val,ask2(p1,l,r));
	if(r>mid) val =max(val,ask2(p2,l,r));
	return val;
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	cin>>T>>n;
	//if(T==0) {cout<<8;return 0;}
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) cin>>b[i];
	cin>>Q;
	build1(1,1,n);
	build2(1,1,n);
	while(Q--){
		int l,r;cin>>l>>r;
		for(int i=l;i<=r;i++)
			for(int j=i;j<=r;j++){
				ll val=ask1(1,i,j);
				ans=(ans+val*ask2(1,i,j));
			}
		cout<<ans<<endl;
		ans=0;
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}