#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,x,y,z) for(long long i=x;i<=y;i+=z)
#define fd(i,x,y,z) for(long long i=x;i>=y;i-=z)
ll T,n;
ll a[200005],b[200005];
ll q;
unsigned long long ans=0;
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%lld%lld",&T,&n);
	f(i,1,n,1){
		scanf("%lld",&a[i]);
	}
	f(i,1,n,1){
		scanf("%lld",&b[i]);
	}
	scanf("%lld",&q);
	while(q--){
		ans=0;
		ll xx,yy;
		scanf("%lld%lld",&xx,&yy);
		f(i,xx,yy,1){
			f(j,xx,yy,1){
				unsigned long long mxa=0,mxb=0;
				f(k,i,j,1){
					mxa=max(mxa,(unsigned long long)a[k]);
					mxb=max(mxb,(unsigned long long)b[k]);
				}
				ans+=mxa*mxb;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
/*
Oh,I can't do it.
So could give me 30pts?
*/