#include<bits/stdc++.h>
#define mk make_pair
#define I inline
#define RI register int
#define rep(i,a,b) for(RI i=a;i<=b;++i)
#define dow(i,a,b) for(RI i=a;i>=b;--i)
using namespace std;
const int N=2e6+5;
int Q,T,l,r,n,k,m,top,a[N],b[N];

int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%d%d",&T,&n);
	rep(i,1,n) scanf("%d",&a[i]);
	rep(i,1,n) scanf("%d",&b[i]);
	scanf("%d",&Q);
	while(Q--){
		scanf("%d%d",&l,&r);
		unsigned long long ans=0;
		rep(i,l,r){
			RI ma1=0,ma2=0;
			rep(j,i,r){
				ma1=max(ma1,a[j]),ma2=max(ma2,b[j]);
				ans+=1ull*ma1*ma2;
			}
		}
		printf("%llu\n",ans);
	}
	return 0;
}