#include<iostream>
#define ll long long
using namespace std;
int read(){
	int w=0,f=1;
	char c=getchar();
	if(c<'0'||c>'9'){
		f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		w=w*10+c-'0';
		c=getchar();
	}
	return w*f;
}
void write(int x){
	if(x<0){
		putchar('-');
		x*=-1;
	}
	if(x>=10){
		write(x/10);
	}
	putchar(x%10+'0');
}
const int N=3*1e5+5,inf=0x3f3f3f3f;
int t,n,q;
ll ans;
ll a[N],b[N];
ll max1(int x,int y){
	ll maxn=-inf;
	for(int i=x;i<=y;i++){
		maxn=max(a[i],maxn);
	}
	return maxn;
}
ll max2(int x,int y){
	ll maxn=-inf;
	for(int i=x;i<=y;i++){
		maxn=max(b[i],maxn);
	}
	return maxn;
}
int 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();
	}
	for(int i=1;i<=n;i++){
		b[i]=read();
	}
	q=read();
	for(int i=1;i<=q;i++){
		ans=0;
		int l=read(),r=read();
		for(int j=l;j<=r;j++){
			for(int k=j;k<=r;k++){
				ans+=max1(j,k)*max2(j,k);
			}
		}
		write(ans);
		putchar(10);
	}
	return 0;
}
