#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N=1e4+9;
int n,m,q,T,a[N],b[N],Q;
struct node{
	int l,r;
	ll maxn;
}t1[4*N],t2[4*N];
void build1(int p,int l,int r){
	t1[p].l=l,t1[p].r=r;
	if (l==r){
		t1[p].maxn=a[l];
		return;
	}
	int mid=(l+r)/2;
	build1(p*2,l,mid);
	build1(p*2+1,mid+1,r);
	t1[p].maxn=max(t1[p*2].maxn,t1[p*2+1].maxn);
}
void build2(int p,int l,int r){
	t2[p].l=l,t2[p].r=r;
	if (l==r){
		t2[p].maxn=b[l];
		return;
	}
	int mid=(l+r)/2;
	build2(p*2,l,mid);
	build2(p*2+1,mid+1,r);
	t2[p].maxn=max(t2[p*2].maxn,t2[p*2+1].maxn);
}
ll ask1(int p,int l,int r){
	if (l<=t1[p].l&&t1[p].r<=r){
		return t1[p].maxn;
	}
	int mid=(t1[p].l+t1[p].r)/2;
	ll ma=0;
	if (l<=mid) ma=max(ma,ask1(p*2,l,r));
	if (r>mid) ma=max(ask1(p*2+1,l,r),ma);
	return ma;
}
ll ask2(int p,int l,int r){
	if (l<=t2[p].l&&t2[p].r<=r){
		return t2[p].maxn;
	}
	int mid=(t2[p].l+t2[p].r)/2;
	ll ma=0;
	if (l<=mid) ma=max(ma,ask2(p*2,l,r));
	if (r>mid) ma=max(ask2(p*2+1,l,r),ma);
	return ma;
}
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("%d",&a[i]);
	for (int i=1;i<=n;i++){
		scanf("%d",&b[i]);
	}
	build1(1,1,n);
	build2(1,1,n);
	//cout<<t1[1].maxn<<' '<<t2[1].maxn<<endl;
	scanf("%d",&Q);
	while(Q--){
		ull ans=0;
		int l,r;
		scanf("%d%d",&l,&r);
		for (int i=l;i<=r;i++){
			for (int j=i;j<=r;j++){
				ans+=(ask1(1,i,j)*ask2(1,i,j));
			}
		}
		printf("%llu\n",ans);
	}
	return 0;
}