#include<bits/stdc++.h>
#define up(i,x,y) for (int (i)=(x);(i)<=(y);(i)++)
#define down(i,x,y) for (int (i)=(x);(i)>=(y);(i)--)
#define ll long long
#define elif else if
using namespace std;
int read(){
	int x=0;
	char c=getchar();
	bool f=0;
	while (c<'0' or c>'9') {
		if (c=='-') f=1;
		c=getchar();
	}
	while (c>='0' and c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return (f?-x:x);
}
void print(unsigned long long x){
	if (x>9) print(x/10);
	putchar('0'+x%10);
}
int t,n,a[19][250010],b[19][250010],lg[250010],m,l,r;
unsigned long long ans,ap,bp;
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	t=read(),n=read();
	lg[0]=-1;
	up(i,1,n) a[0][i]=read(),lg[i]=lg[(i>>1)]+1;
	up(i,1,n) b[0][i]=read();
	for (int i=1;i<=lg[n];i++){
		for (int j=1;j<=n+1-(1<<i);j++){
			a[i][j]=max(a[i-1][j],a[i-1][j+(1<<(i-1))]);
			b[i][j]=max(b[i-1][j],b[i-1][j+(1<<(i-1))]);
		}
	}
	m=read();
	up(i,1,m){
		l=read(),r=read();
		ans=0;
		up(p,l,r) up(q,p,r){
			ap=max(a[lg[q-p+1]][p],a[lg[q-p+1]][q-(1<<lg[q-p+1])+1]);
			bp=max(b[lg[q-p+1]][p],b[lg[q-p+1]][q-(1<<lg[q-p+1])+1]);
			ans+=(ap*bp);
		}
		print(ans);
		printf("\n");
	}
	fclose(stdin);
	fclose(stdout);
}