#include<bits/stdc++.h>
using namespace std;
#define int long long
struct reader{
	#define gc ch=getchar()
	template<typename T>
	reader&operator>>(T&x){
		char gc;x=0;int f=1;
		for(;!isdigit(ch);gc)ch=='-'&&(f=-f);
		for(;isdigit(ch);gc)x=x*10+ch-'0';
		x*=f;return*this;
	}
}fin;
const int N=500005;
int n,a[N],b[N],T,ma,mb,Q,l,r,ans;
signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
//	freopen("match2.in","r",stdin);
//	freopen("match2.out","w",stdout);
	fin>>T>>n;
	for(int i=1;i<=n;i++)fin>>a[i];
	for(int i=1;i<=n;i++)fin>>b[i];
	fin>>Q;
	while(Q--){
		fin>>l>>r;ans=0;
		for(int p=l;p<=r;p++){
			for(int q=p;q<=r;q++){
				ma=mb=0;
				for(int i=p;i<=q;i++)ma=max(ma,a[i]),mb=max(mb,b[i]);
				ans+=ma*mb;
			}
		}
		printf("%lld\n",ans);
	}
}