#include<bits/stdc++.h>
using namespace std;
int T,n,q;
int a[250005],b[250005];
unsigned long long ans;
inline int read(){
	int ret=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
	while(isdigit(ch)){ret=ret*10+ch-'0';ch=getchar();}
	return ret*f;
}
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();
	while(q--){
		int l=read(),r=read();
		for(int i=l;i<=r;i++){
			int maxa=a[i],maxb=b[i];
			for(int j=i;j<=r;j++){
				maxa=max(maxa,a[j]);maxb=max(maxb,b[j]);
				ans=ans+(unsigned long long)maxa*maxb;
			}
		}
		cout<<ans<<'\n';
		ans=0;
	}
	return 0;
}