#include<bits/stdc++.h>
int t,n,q,f[250005],g[250005],s[3005][3005];
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int t,n;
	scanf("%d%d",&t,&n);
	for (int i=1;i<=n;i++) scanf("%d",&f[i]);
	for (int i=1;i<=n;i++) scanf("%d",&g[i]);
	for (int i=1;i<=n;i++)
	{
		unsigned long long m1=0,m2=0;
		for (int j=i;j<=n;j++)
		{
			m1=std::max(m1,(unsigned long long)f[j]),
			m2=std::max(m2,(unsigned long long)g[j]);
			s[i][j]=m1*m2;
		}
	}
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			s[i][j]=s[i][j]+s[i-1][j]+s[i][j-1]-s[i-1][j-1];
	scanf("%d",&q);
	while (q--)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		unsigned long long ans=0;
//		for (int x=l;x<=r;x++)
//			for (int y=x;y<=r;y++)
//				ans=ans+s[x][y];
		ans=s[r][r]-s[l-1][r]-s[r][l-1]+s[l-1][l-1];
		printf("%llu\n",ans);
	}
	return 0;
}