#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
inline ll read(){
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x*f;
}
const int N=100010;
ll T,n,m,a[N],b[N],ans;
ll query(ll x,ll y){
	ll res=0;
	for(ll i=x;i<=y;i++)
		for(ll j=i,u=0,v=0;j<=y;j++){
			for(ll k=i;k<=j;k++)u=max(u,a[k]);
			for(ll k=i;k<=j;k++)v=max(v,b[k]);
			res+=u*v;
		}
	return res;
}
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	T=read(),n=read();
	for(ll i=1;i<=n;i++)a[i]=read();
	for(ll i=1;i<=n;i++)b[i]=read();
	m=read();
	for(ll _=1,x,y;_<=m;_++)
		x=read(),y=read(),
		printf("%llu\n",query(x,y));
	return 0;
}