#include<bits/stdc++.h>
using namespace std;
#define ll long long
int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while('0'<=c&&c<='9'){
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	return x*f;
}
const int N=3000+10;
int id,n,Q,l,r;
ll ans=0;
int a[N],b[N];
void putin(){
	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();
}
int afind(int l,int r){
	int res=l;
	for(int i=l;i<=r;i++){
		if(a[res]<a[i]){
			res=i;
		}
	}
	return a[res];
}
int bfind(int l,int r){
	int res=l;
	for(int i=l;i<=r;i++){
		if(b[res]<b[i]){
			res=i;
		}
	}
	return b[res];
}
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	putin();
	while(Q--){
		ans=0;
		l=read();r=read();
		for(int p=l;p<=r;p++){
			for(int q=p;q<=r;q++){
				ans+=afind(p,q)*bfind(p,q);
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}
