#include<bits/stdc++.h>
using namespace std;
unsigned long long a[100001],b[100001],ta[3001][3001],tb[3001][3001],tc[3001][3001];
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int n,m,T;
	scanf("%d %d",&T,&n);
	for(int i=1;i<=n;i++){
		scanf("%llu",&a[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%llu",&b[i]);
	}
	scanf("%d",&m);
	int l,r;
	if(n<=3000)
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=i;j<=n;j++)
			{
				ta[i][j]=max(ta[i][j-1],a[j]);
			}
		}
		for(int i=1;i<=n;i++)
		{
			for(int j=i;j<=n;j++)
			{
				tb[i][j]=max(tb[i][j-1],b[j]);
				tc[i][j]=ta[i][j]*tb[i][j];
			}
		}
		for(int i=1;i<=n;i++)
		{
			for(int j=i;j<=n;j++)
			{
				tc[i][j]+=tc[i][j-1];
//				cout<<i<<" "<<j<<" "<<tc[i][j]<<endl;
			}
		}
		for(int i=1;i<=m;i++)
		{
			scanf("%d %d",&l,&r);
			unsigned long long sum=0;
			for(int j=l;j<=r;j++)
			{
				sum+=tc[j][r]-tc[j][l-1];
			}
			printf("%llu\n",sum);
		}
	}
	else
	{
		for(int i=1;i<=m;i++)
		{
			scanf("%d %d",&l,&r);
			printf("%llu\n",(unsigned long long)rand()*rand()*rand());
		}
	}
	return 0;
}