#include<bits/stdc++.h>
using namespace std;
unsigned long long dp[5005][5005];
unsigned long long a[5005],b[5005];
int read(){
	int f=1,l=0;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		l=l*10+(c-'0');
		c=getchar();
	}
	return f*l;
}
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n=read();
	n=read();
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<=n;i++)
	{
		unsigned long long ma=0,mb=0; 
		for(int j=i;j<=n;j++)
		{
			ma=max(ma,a[i]);
			mb=max(mb,b[i]);
			dp[i][j]=ma*mb+dp[i][j-1];
		}
	}
	int q=read();
	while(q--){
		int l=read();
		int r=read();
		unsigned long long ans=0;
		for(int i=l;i<=r;i++)
			ans+=dp[l][r];
		cout<<ans<<endl;
	}
	return 0;
}