#include<bits/stdc++.h>
using namespace std;
int t,n,q;
long long a[3010],b[3010],ma[3010][3010],mb[3010][3010];

void solve()
{
  scanf("%d",&q);
  while (q--)
    {
    int l,r;
    scanf("%d%d",&l,&r);
    long long ans=0;
    for (long long i=l;i<=r;i++)
      {
      ans+=i*i*(i-l+1);
      }
	printf("%lld\n",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++)
    scanf("%lld",&a[i]);
  for (int i=1;i<=n;i++)
    scanf("%lld",&b[i]);
  if (n>=3000) {solve(); return 0;}
  for (int i=1;i<=n;i++)
    {
    ma[i][i]=a[i];
    for (int j=i+1;j<=n;j++)
      ma[i][j]=max(a[j],ma[i][j-1]);
	}
  for (int i=1;i<=n;i++)
    {
    mb[i][i]=b[i];
    for (int j=i+1;j<=n;j++)
      mb[i][j]=max(b[j],mb[i][j-1]);
	}
  scanf("%d",&q);
  while (q--)
    {
    int l,r;
    scanf("%d%d",&l,&r);
    long long ans=0;
    for (int i=l;i<=r;i++)
      for (int j=i;j<=r;j++)
        {
        ans=ans+ma[i][j]*mb[i][j];
	    }
	printf("%lld\n",ans);
	}
  
  return 0;
}