#include <bits/stdc++.h>
using namespace std;
unsigned long long a[500010],b[500010],s[3010][3010];
int main()
{
	freopen("match.in","r",stdin);freopen("match.out","w",stdout);
	int T,n,q;scanf("%d%d",&T,&n);for(int i=1;i<=n;i++) scanf("%u",&a[i]);for(int i=1;i<=n;i++) scanf("%u",&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[j]),mb=max(mb,b[j]);
			s[i][j]=ma*mb;
		}
	}
	scanf("%d",&q);while(q--)
	{
		int l,r;unsigned long long ans=0;
		scanf("%d%d",&l,&r);for(int i=l;i<=r;i++) for(int j=i;j<=r;j++) ans+=s[i][j];
		printf("%u\n",ans);
	}
	return 0;
}