#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=LLONG_MAX;
int T,n,Q;
int ans;
int a[3001],b[3001],l[3001],r[3001];
signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%d%d",&T,&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)scanf("%d",&b[i]);
	scanf("%d",&Q);
	for(int i=1;i<=Q;i++)scanf("%d%d",&l[i],&r[i]);
	for(int i=1;i<=Q;i++){
		ans=0;
		for(int po=l[i];po<=r[i];po++){
			for(int qo=l[i];qo<=r[i];qo++){
				int maxa=0,maxb=0;
				for(int k=po;k<=qo;k++)maxa=max(maxa,a[k]),maxb=max(maxb,b[k]);
				ans+=(maxa*maxb)%mod;
			}
		}
	printf("%d\n",ans%mod);	
	}
	return 0;
}