#include<bits/stdc++.h>
using namespace std;
inline long long read(){
	long long x=0,f=1;char ch=getchar();
	while ((!isdigit(ch))&&(ch!='-')) ch=getchar();
	if (ch=='-') f=-1,ch=getchar();
	while (isdigit(ch)) x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return x*f;
}
unsigned long long a[1001010],b[1001010],mx1,mx2,ans;
long long l,r,n,i,j,Q;
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int testid=read();n=read();
	for (i=1;i<=n;i++) a[i]=read();
	for (i=1;i<=n;i++) b[i]=read();
	Q=read();
	for (;Q;Q--){
		l=read();r=read();
		ans=0;
		for (i=l;i<=r;i++){
			mx1=mx2=0;
			for (j=i;j<=r;j++){
				mx1=max(mx1,a[j]);
				mx2=max(mx2,b[j]);
				ans=ans+mx1*mx2;
			}
		}
		printf("%llu\n",ans);
	}
	return 0;
}
