#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int read(){
	int res=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') f=-f;ch=getchar();}
	while(isdigit(ch)) {res=res*10+(ch-'0');ch=getchar();}
	return res*f;
}
//10:10
//10:30
const int maxn=3e5;
int n,a[maxn],b[maxn];
ull res[3010][3010];
ull amx[3010][25],bmx[3010][25];
int maxa(int l,int r){
	int k=log2(r-l+1);
	return max(amx[l][k],amx[r-(1<<k)+1][k]);
}
int maxb(int l,int r){
	int k=log2(r-l+1);
	return max(bmx[l][k],bmx[r-(1<<k)+1][k]);
}
signed main(){
	//system("fc D:\\match3.ans D:\\match3.out");
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int t=read();
	n=read();
	for(int i=1;i<=n;i++)a[i]=read(),amx[i][0]=a[i];
	for(int j=1;j<=n;j++)b[j]=read(),bmx[j][0]=b[j];
	
	
	for(int j=1;j<21;j++){
		for(int i=1;i+(1<<j)-1<=n;i++){
			amx[i][j]=max(amx[i][j-1],amx[i+(1<<(j-1))][j-1]);
			bmx[i][j]=max(bmx[i][j-1],bmx[i+(1<<(j-1))][j-1]);
		}
	}
	
	for(int i=1;i<=n;i++) for(int j=i;j<=n;j++){
		res[i][j]=1ull*maxa(i,j)*maxb(i,j);
	}
	int Q=read();
	while(Q--){
		int l=read(),r=read();
		ull ans=0;
		for(int i=l;i<=r;i++) for(int j=i;j<=r;j++) ans+=res[i][j];
		cout<<ans<<"\n";
	}
	return 0;
}/*

0 2
2 1
1 2
1
1 2
*/

