#include<iostream>
#include<cstring>
#include<cstdio>
#define int unsigned long long
using namespace std;
const int N=3e5+5,M=2e6+5,mod=998244353;

int read(){
	char c=getchar();int f=1,x=0;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-48;c=getchar();}
	return x*f;
}

int t,n,q,ll,rr,ans,a[N],b[N];

int treea[N],treeb[N];
int ls(int p){return p<<1;}
int rs(int p){return p<<1|1;}
void push_upa(int p){treea[p]=max(treea[ls(p)],treea[rs(p)]);}
void push_upb(int p){treeb[p]=max(treeb[ls(p)],treeb[rs(p)]);}
void builda(int p,int l,int r){
	if(l==r){treea[p]=a[l];return ;}
	int mid=(l+r)>>1;
	builda(ls(p),l,mid);
	builda(rs(p),mid+1,r);
	push_upa(p);
}
void buildb(int p,int l,int r){
	if(l==r){treeb[p]=b[l];return ;}
	int mid=(l+r)>>1;
	buildb(ls(p),l,mid);
	buildb(rs(p),mid+1,r);
	push_upb(p);
}
int querya(int p,int nl,int nr,int l,int r){
	if(nl<=l&&nr>=r)return treea[p];
	int res=0;
	int mid=(l+r)>>1;
	if(nl<=mid)res=max(res,querya(ls(p),nl,nr,l,mid));
	if(nr>mid)res=max(res,querya(rs(p),nl,nr,mid+1,r));
	return res;
}
int queryb(int p,int nl,int nr,int l,int r){
	if(nl<=l&&nr>=r)return treeb[p];
	int res=0;
	int mid=(l+r)>>1;
	if(nl<=mid)res=max(res,queryb(ls(p),nl,nr,l,mid));
	if(nr>mid)res=max(res,queryb(rs(p),nl,nr,mid+1,r));
	return res;
}

signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	t=read(),n=read();
	for(int i=1;i<=n;++i)a[i]=read();
	builda(1,1,n);
	for(int i=1;i<=n;++i)b[i]=read();
	buildb(1,1,n);
	q=read();
//	cout<<1<<endl;
//	cout<<querya(1,1,n,1,n)<<endl;
//	cout<<2<<endl;
	while(q--){
		ll=read(),rr=read(),ans=0;
		for(int i=ll;i<=rr;++i){
			for(int j=i;j<=rr;++j){
				ans+=querya(1,i,j,1,n)*queryb(1,i,j,1,n);
//				cout<<i<<" "<<j<<" ";
//				cout<<querya(1,i,j,1,n)<<" "<<queryb(1,i,j,1,n)<<endl;
			}
		}
//		printf("%ull\n",ans);
		cout<<ans<<endl;
	}
//	cout<<ans<<endl;
	return 0;
}
