#include<bits/stdc++.h>
using namespace std;
inline int read(){
	char ch=getchar();int x=0;bool f=0;
	for(;!isdigit(ch);ch=getchar())if(ch=='-')f=1;
	for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
	if(f){x=-x;}return x;
}
#define int long long
const int mod=998244353;
const int maxn=3e5+5;
int n,m,q,l,r,c[maxn],id;
unsigned long long ans=0,a[maxn],b[maxn],s1,s2;
signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	id=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++){
		l=read(),r=read();ans=0;
		for(int j=l;j<=r;j++){
			s1=a[j],s2=b[j];
			for(int k=j;k<=r;k++){
				s1=max(s1,a[k]),s2=max(s2,b[k]);
				ans=ans+s1*s2;
				//cout<<s1<<" "<<s2<<endl;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
