#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
long long a[25005],b[25005],l,r;
int main()
{
 	freopen("match.in","r",stdin);
 	freopen("match.out","w",stdout);
 	int T,n;
 	cin>>T>>n;
 	for(int i=1;i<=n;i++)
 	{
 		scanf("%d",&a[i]);
	 }
	 for(int i=1;i<=n;i++)
	 {
	 	scanf("%d",&b[i]);
	 }
	 int Q;
	 cin>>Q;
	 while(Q--)
	 {
	 	scanf("%d%d",&l,&r);
		long long ans=0,maa,mbb,ma,mb;
		for(int p=l;p<=r;p++)
		{
			ma=-1,mb=-1,maa=0,mbb=0;
			for(int q=p;q<=r;q++)
			{
				for(int j=p;j<=q;j++)
				{
					if(maa&&mbb)
					{
						if(a[q]>ma)
						{
							ma=a[q];
							maa=q;
						}
						if(b[q]>mb)
						{
							mb=b[q];
							mbb=q;
						}
						break;
					}
					if(a[j]>ma) 
					{
						ma=a[j];
						maa=j;
					}
					if(b[j]>mb) 
					{
						mb=b[j];
						mbb=j;
					}
				}
				ans+=ma*mb;
			}
		}
		cout<<ans<<endl;
	 }
	 
 	return 0;
}
