#include<iostream>
using namespace std;
int n,t,q;
int a[250005],b[250005];
int aa[250005],bb[250005];//最大位置线段树
//unsigned long long ans;
int fmx(int nums[],int l,int r)//返回位置
{
    int ans=l;
    for(int i=l+1;i<=r;i++)
    {
        if(nums[ans]<nums[i])
        {
            ans=i;
        }
    }
    return ans;
}
void make()
{
    for(int i=1;i<=n;i++)
    {
        int tmp=(i&-i)>>1;
        aa[i]=i;
        while(tmp>0)
        {
            if (a[aa[i]]<a[aa[i-tmp]])
            {
                aa[i]=aa[i-tmp];
            }
            tmp=tmp>>1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        int tmp=(i&-i)>>1;
        bb[i]=i;
        while(tmp>0)
        {
            if (b[bb[i]]<b[bb[i-tmp]])
            {
                bb[i]=bb[i-tmp];
            }
            tmp=tmp>>1;
        }
    }
}
int fmx2a(int l,int r)
{
    if(l>r)return -1;
    int p=r;
    int ans=r;
    //cout<<"p "<<p<<"l "<<l<<endl;
    while(p>=l)
    {
        //cout<<"p "<<p<<" "<<(p&-p)<<endl;
        if(p-(p&-p)>=l)
        {
            if(a[aa[p]]>a[ans])
            {
                ans=aa[p];
            }
            p=p-(p&-p);
        }
        else
        {
            if(a[p]>a[ans])
            {
                ans=p;
            }
            p=p-1;
        }
       
    }
    return ans;
}
int fmx2b(int l,int r)
{
    if(l>r)return -1;
    int p=r;
    int ans=r;
    //cout<<"p "<<p<<"l "<<l<<endl;
    while(p>=l)
    {
        //cout<<"p "<<p<<" "<<(p&-p)<<endl;
        if(p-(p&-p)>=l)
        {
            if(b[bb[p]]>b[ans])
            {
                ans=bb[p];
            }
            p=p-(p&-p);
        }
        else
        {
            if(b[p]>b[ans])
            {
                ans=p;
            }
            p=p-1;
        }
       
    }
    return ans;
}
long long search(int l,int r)
{
    if(l>r)return 0;
    //cout<<" dbg "<<l<<" "<<r<<endl;
    long long ans=0;
    int pa,pb,max1,max2;
    pa=fmx2a(l,r);
    pb=fmx2b(l,r);
    max1=a[pa];
    max2=b[pb];
    int d1,d2;
    if (pa==pb)
    {
        d1=pa;
        d2=pb;
    }
    else if(pa<pb)
    {
        d1=pa;
        d2=pb;
    }
    else
    {
        d1=pb;
        d2=pa;
    }
    ans+=(d1-l+1)*(r-d2+1)*max1*max2;
    //cout<<" dbg "<<l<<" "<<r<<" "<<max1*max2<<" "<<ans<<endl;
    //cout<<max1<<" "<<max2<<endl;
    ans+=search(l,d2-1);
    ans+=search(d1+1,r);
    ans-=search(d1+1,d2-1);
    return ans;
}

int main()
{
    freopen("match.in","r",stdin);
    freopen("match.ans","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];
    }
    /*for(int i=1;i<=n;i++){
        cout<<a[i]<<" ";
    }
    cout<<endl;
    for(int i=1;i<=n;i++){
        cout<<b[i]<<" ";
    }
    cout<<endl;*/
    make();
    cin>>q;
    for(int i=1;i<=q;i++)
    {
        int l,r;
        cin>>l>>r;
        //cout<<l<<r;
        cout<<search(l,r)<<endl;
        //cout<<ans<<endl;
        //ans=0;
    }
    
    return 0;
}