#include<bits/stdc++.h>
using namespace std;
#define murder 18446744073709551616;
int n,q,a[10000],b[10000],c[10000],d[10000];
inline int read()
{
int s=0,w=1;
char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') w=-1;
for(;isdigit(c);c=getchar()) s=(s<<3)+(s<<1)+(c^48);
return s*w;}
bool cmp(int x,int y)
{if(x>y) return 1;
return 0;}
int main()
{
freopen("match.in","r",stdin);
freopen("match.out","w",stdout);
int id=read();n=read();
for(int i=1;i<=n;i++) a[i]=read();
for(int i=1;i<=n;i++) b[i]=read();
int T=read();
while(T--)
  {long long sum=0;
   int l=read(),r=read();
   for(int i=l;i<=r;i++)
     for(int j=i;j<=r;j++)
       {
       	for(int K=i;K<=j;K++) c[K-i+1]=a[K];
        for(int K=i;K<=j;K++) d[K-i+1]=b[K];
        q=j-i+1;
		sort(c+1,c+1+q,cmp);
		sort(d+1,d+1+q,cmp);
        sum=sum+c[1]*d[1];
	   }
   printf("%lld",sum);
  }
return 0;
}