#include<bits/stdc++.h>
using namespace std;
int i,j,n,a[300000],b[300000],t,q,z,l,r;
long long sum,summ;
int ffn(int x,int y)
{
	int s,ii;
	s=-1;
	for (ii=x;ii<=y;ii++) s=max(s,a[ii]);
	return s;
}
int ffo(int x,int y)
{
	int s,ii;
	s=-1;
	for (ii=x;ii<=y;ii++) s=max(s,b[ii]);
	return s;
}
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
    cin>>t>>n;
    for (i=1;i<=n;i++) cin>>a[i];
    for (i=1;i<=n;i++) cin>>b[i];
    cin>>q;
    for (z=1;z<=q;z++)
    {
    	sum=0;
    	cin>>l>>r;
    	for (i=l;i<=r;i++)
    	{
    		for (j=i;j<=r;j++)
    		{
    			sum=(sum+ffn(i,j)*ffo(i,j));
			}
		}
		cout<<sum<<endl;
	}
}