#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;

int n,q,T;
ull a[250005],b[250005],posa[250005],posb[200005],ans,v[3005][3005];

void sol1(){
	for(int l = 1; l <= n; l++){
		ull x=0,y=0;
		for(int r = l; r <= n; r++){
			x = max(x,a[r]);
			y = max(y,b[r]);
			v[l][r]=x*y;
			v[l][r]+=v[l][r-1];
		}
	}
	while(q--){
		int l,r;
		ans = 0;
		scanf("%d%d",&l,&r);
		for(int i = l; i <= r; i++)ans+=v[i][r]-v[i][l-1];
		printf("%llu\n",ans);
	}
}

int val[1000005],sum[1000005];

int add(int l, int r, int x, int pos){
	if(l==r){
		return 0;
	}
	return 0;
}

void sol2(){
	
}

int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%d%d",&T,&n);
	for(int i = 1; i <= n; i++)scanf("%llu",&a[i]);
	for(int i = 1; i <= n; i++)scanf("%llu",&b[i]);
	scanf("%d",&q);
	if(n<=3000&&q<=3000)sol1();
	else sol2();
	return 0;
}