#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;

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

int T,n,a[N],b[N];

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();
	int Q=read();
	while (Q--){
		int l=read(),r=read();
		ull ans=0;
		for (int p=l;p<=r;++p){
			int Mxp=0,Mxq=0;
			for (int q=p;q<=r;++q){
				Mxp=max(Mxp,a[q]);
				Mxq=max(Mxq,b[q]);
				ans=ans+1ull*Mxp*Mxq;
			}
		}
		printf("%llu\n",ans);
	}
	return 0;
}
