#include<bits/stdc++.h>
using namespace std;
long long ans;
int T,n,a[100001],b[100001],ans1,ans2,l,r,q;
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;
	for (int i=1;i<=q;i++)
	{
		cin>>l>>r;ans=0;
		for (int j=l;j<=r;j++)
		  for (int k=j;k<=r;k++)
		  {
		    ans1=0;ans2=0;
		    //cout<<j<<' '<<k;
		    for (int ii=j;ii<=k;ii++)
		    {
		    	ans1=max(a[ii],ans1);
		    	ans2=max(b[ii],ans2);
			}
			ans+=ans1*ans2;
	      }
	    cout<<ans<<endl;
    }
}
