#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N=1e6+10;
int a[N][25],b[N][25];
int lg[N];
int t,n,q;
ull ans;
int read(){
	int x=0,f=1;
	char ch=getchar();
	while (ch<'0'||ch>'9'){
		if (ch=='-') f=-f;
		ch=getchar();
	}
	while (ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
void write(ull x){
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	t=read(),n=read();
	for (int i=2;i<=n;i++) lg[i]=lg[i/2]+1;
	for (int i=1;i<=n;i++) a[i][0]=read();
	for (int i=1;i<=n;i++) b[i][0]=read();
	for (int j=1;j<=18;j++){
		for (int i=1;i<=n;i++){
			a[i][j]=max(a[i][j-1],a[i+(1<<(j-1))][j-1]);
			b[i][j]=max(b[i][j-1],b[i+(1<<(j-1))][j-1]);
		}
	}
	q=read();
	while(q--){
		ans=0;
		int l=read(),r=read();
		for (int i=l;i<=r;i++){
			for (int j=i;j<=r;j++){
				t=lg[j-i+1];
				ans+=max(a[i][t],a[j-(1<<t)+1][t])*max(b[i][t],b[j-(1<<t)+1][t]);
			}
		}
		write(ans);
		putchar('\n');
	}
	//The bloody dusk and The pale dawn.
	fclose(stdin);
	fclose(stdout);
	return 0;
}
