#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
int a[1000000];
int b[1000000];
unsigned long long st[2][1000000][20];
unsigned long long rmq(int id,int l,int r){
	if(l==r) return st[id][l][0];
	int s=log2(r-l+1);
	return max(st[id][l][s],st[id][r-(1<<s)+1][s]);
}
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int T,n;
	scanf("%d%d",&T,&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),st[0][i][0]=(ull)a[i];
	for(int i=1;i<=n;i++) scanf("%d",&b[i]),st[1][i][0]=(ull)b[i];
	for(int k=0;k<2;k++)
		for(int j=1;j<=20;j++)
			for(int i=1;i+(1<<(j-1))<=n;i++){
				st[k][i][j]=max(st[k][i][j-1],st[k][i+(1<<(j-1))][j-1]);
		}
	int q;
	scanf("%d",&q);
	while(q--){
		unsigned long long ans=0;
		int l,r;
		scanf("%d%d",&l,&r);
		for(int p=l;p<=r;p++)
			for(int q=p;q<=r;q++){
				ans+=(rmq(0,p,q))*(rmq(1,p,q));
			}
		cout<<ans,putchar('\n');	
	}
	return 0;
}