#include <cstdio>
#include <iostream>
using namespace std;
int t,n,q,l,r;
unsigned long long a[2000010],b[2000010],ans,maxta,maxtb;
unsigned long long read()
{
	 unsigned long long ans=0;
	 char c;
	 c=getchar();
	 while ((c>'9')||(c<'0'))
	  c=getchar();
	 while ((c<='9')&&(c>='0'))
	   ans=(ans<<1)+(ans<<3)+(c-'0'),c=getchar();
	   return ans;
}
 int main()
 {
 	 freopen("match.in","r",stdin);
 	 freopen("match.out","w",stdout);
 	  scanf("%d%d",&t,&n);
 	   for (int i=1;i<=n;i++)
 	    a[i]=read();
 	   for (int i=1;i<=n;i++)
 	    b[i]=read();
 	scanf("%d",&q);
 	while (q--)
 	{
 		 ans=0;
 		 scanf("%d%d",&l,&r);
 		  for (int i=l;i<=r;i++)
 		  {
 		    maxta=a[i];
 		    maxtb=b[i];
 		   for (int j=i;j<=r;j++)
 		   {
 		   	 maxta=max(maxta,a[j]);
 		   	 maxtb=max(maxtb,b[j]);
 		     ans=ans+maxta*maxtb;
 	       }
 	      }
 	      cout<<ans;
 	      printf("\n");
	}
 	 fclose(stdin);
 	 fclose(stdout);
 	 return 0;
 }