#include<bits/stdc++.h>
#define int long long
using namespace std;
//const int mod=18446744073709551616;
int t,n,q,l,r,a[250005],b[250005],sum1,sum2,ans;
int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch>'9'||ch<'0')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch<='9'&&ch>='0')
	{
		x=x*10+ch-48;
		ch=getchar();
	}
	return x*f;
}
signed main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	cin>>t>>n;
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=n;i++)b[i]=read();
	cin>>q;
	while(q--)
	{
		cin>>l>>r;
		ans=0;
		for(int i=l;i<=r;i++)
			for(int j=i;j<=r;j++)
			{
				sum1=0;sum2=0;
				for(int k=i;k<=j;k++)
				{
					if(a[k]>sum1)sum1=a[k];
					if(b[k]>sum2)sum2=b[k];
				}
				ans=(ans+sum1*sum2);//%mod;
			}
		cout<<ans<<endl;
	}
	return 0;
}
