#include <bits/stdc++.h>
#define ll
using namespace std;
const int N=250010;
const long long int M=4294967296;
int t,n,a[N],b[N],q,l,r;
inline int read(){
	int f=1,sum=0;
	char ch=getchar();
	while(ch<'0' || ch>'9'){
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0' && ch<='9'){
		sum=sum*10+(int(ch-'0'));
		ch=getchar();
	}
	return sum*f;
}
struct tree{
	int left,right,data;
}aa[N*4],bb[N*4];

void build1(int p,int left,int right){
	aa[p].left=left;
	aa[p].right=right;
	if(left==right){
		aa[p].data=a[left];
		return;
	}
	int mid=(left+right)/2;
	build1(p*2,left,mid);
	build1(p*2+1,mid+1,right);
	aa[p].data=max(aa[p*2].data,aa[p*2+1].data);
	return;
}
void build2(int p,int left,int right){
	bb[p].left=left;
	bb[p].right=right;
	if(left==right){
		bb[p].data=b[left];
		return;
	}
	int mid=(left+right)/2;
	build2(p*2,left,mid);
	build2(p*2+1,mid+1,right);
	bb[p].data=max(bb[p*2].data,bb[p*2+1].data);
	return;
}

int ask1(int p,int left,int right){
	if(left<=aa[p].left && right>=aa[p].right){
		return aa[p].data;
	}
	if(left==right){
		return a[left];
	}
	int maxn=-1;
	int mid=(left+right)/2;
	if(left<=mid){
		maxn=max(maxn,ask1(p*2,left,mid));
	}
	if(right>=mid+1){
		maxn=max(maxn,ask1(p*2+1,mid+1,right));
	}
	return maxn;
}

int ask2(int p,int left,int right){
	if(left<=bb[p].left && right>=bb[p].right){
		return bb[p].data;
	}
	if(left==right){
		return b[left];
	}
	int maxn=-1;
	int mid=(left+right)/2;
	if(left<=mid){
		maxn=max(maxn,ask2(p*2,left,mid));
	}
	if(right>=mid+1){
		maxn=max(maxn,ask2(p*2+1,mid+1,right));
	}
	return maxn;
}

int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	t=read(),n=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
	}
	for(int i=1;i<=n;i++){
		b[i]=read();
	}
	build1(1,1,n);
	build2(1,1,n);
	q=read();
	while(q--){
			long long int xxx=0;
			l=read(),r=read();
			long long int max1,max2;
			for(int i=l;i<=r;i++){
				max1=a[i],max2=b[i];
				xxx+=max1*max2;
				long long int xxxx=xxx/M/M;
				xxx=xxx-xxxx*M*M;
				for(int j=i+1;j<=r;j++){
					if(a[j]>max1)
						max1=a[j];
					if(b[j]>max2)
						max2=b[j];
					xxx+=max1*max2;
					long long int xxxx=xxx/M/M;
					xxx=xxx-xxxx*M*M;
				}
			}
			cout<<xxx<<endl;	
	}
	return 0;
}