#include <bits/stdc++.h>
#define N 300919
#define ls(x) x<<1
#define rs(x) (x<<1)|1 
using namespace std;
int n,q,l,r,t;
unsigned long long ans,a[N],b[N];
unsigned long long read(){
	unsigned long long x=0;
	char g=getchar();
	while(!isdigit(g))g=getchar();
	while(isdigit(g)){
		x=(x<<3)+(x<<1)+(g^48);
		g=getchar();
	}
	return x;
}
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	unsigned long long id=read();
	n=read();
	for(int i=1;i<=n;++i)a[i]=read();
	for(int i=1;i<=n;++i)b[i]=read();
	unsigned long long ans=0;
	q=read();
	while(q--){
		unsigned long long ma=0,mb=0;
		l=read(),r=read();
		for(int p=l;p<=r;++p){
			for(int q=p;q<=r;++q){
				for(int i=p;i<=q;++i){
					ma=max(a[i],ma);
					mb=max(b[i],mb);
				}
				ans+=ma*mb;
				ma=0,mb=0;
			}
		}
		cout<<ans<<endl;
		ans=0;
	}
	return 0;
}