#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
int a[3005],b[3005],c[3005],d[3005],k,T,mod=1000000007,n,m,l,r;
long long ans;

int main()
{
     freopen("match.in","r",stdin);
     freopen("match.out","w",stdout);
    cin>>T>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    int Q;
    cin>>Q;
    for(int t=1;t<=Q;t++)
    {
        ans=0;
        cin>>l>>r;
        for(int i=l;i<=r;i++)
        {
            k=a[i]*b[i];
            ans+=k;c[i]=a[i];d[i]=b[i];
        }
        for(int i=l;i<=r;i++)
            for(int j=i+1;j<=r;j++)
            {
                if(c[i]<a[j])c[i]=a[j];
                if(d[i]<b[j])d[i]=b[j];
                ans+=c[i]*d[i];
            }
        cout<<ans;
    }
;
    return 0;
}
