#include<bits/stdc++.h>
using namespace std;
int T,Q,n,a[250005],b[25005];
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	cin>>T>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	cin>>Q;
	while(Q--)
	{
		int l,r;unsigned long long ans=0;
		cin>>l>>r;
		for(int p=l;p<=r;p++)
		{
			int maxa=a[p],maxb=b[p];
			for(int q=p;q<=r;q++)
			{
				maxa=max(maxa,a[q]);
				maxb=max(maxb,b[q]);
				ans+=maxa*maxb;
			}
		}
		cout<<ans<<'\n';
	}
	return 0;
}