#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;
typedef unsigned long long ull;
const int N=3*1e5;

ull ans;

int tra[N<<2],trb[N<<2];
int n,id,Q,l,r;
int a[N],b[N];

int read(){
	int x=0,c=getchar();
	while (c<'0' || c>'9') c=getchar();
	while (c>='0' && c<='9') x=x*10+c-48,c=getchar();
	return x;
}

void builda(int t,int l,int r){
	if (l==r){
		tra[t]=a[l];
		return;
	}
	int mid=l+r>>1;
	builda(t<<1,l,mid);
	builda(t<<1|1,mid+1,r);
	tra[t]=max(tra[t<<1],tra[t<<1|1]);
}

void buildb(int t,int l,int r){
	if (l==r){
		trb[t]=b[l];
		return;
	}
	int mid=l+r>>1;
	buildb(t<<1,l,mid);
	buildb(t<<1|1,mid+1,r);
	trb[t]=max(trb[t<<1],trb[t<<1|1]);
}

int querya(int t,int l,int r,int x,int y){
	if (x<=l && r<=y) return tra[t];
	int mid=l+r>>1,sum=0;
	if (x<=mid) sum=max(sum,querya(t<<1,l,mid,x,y));
	if (y>mid) sum=max(sum,querya(t<<1|1,mid+1,r,x,y));
	return sum;
}

int queryb(int t,int l,int r,int x,int y){
	if (x<=l && r<=y) return trb[t];
	int mid=l+r>>1,sum=0;
	if (x<=mid) sum=max(sum,queryb(t<<1,l,mid,x,y));
	if (y>mid) sum=max(sum,queryb(t<<1|1,mid+1,r,x,y));
	return sum;
}

int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	id=read();n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=1;i<=n;i++) b[i]=read();
	Q=read();
	builda(1,1,n);
	buildb(1,1,n);
	while (Q--){
		ans=0;
		l=read();r=read();
		for (int p=l;p<=r;p++)
			for (int q=p;q<=r;q++)
				ans+=querya(1,1,n,p,q)*queryb(1,1,n,p,q);
		cout<<ans<<endl;
	}
	return 0;
}
