//I'm stupid. I'll AFO.
#include<bits/stdc++.h>
#define ll long long
#define OFFLINE
#define ull unsigned long long
#define l(flag,x) tree[flag][x].l
#define r(flag,x) tree[flag][x].r
#define maxn(flag,x) tree[flag][x].maxn
using namespace std;
const int MAXN=3e5+3;
struct Node{
    int l,r;
    ull maxn;
};
Node tree[2][4*MAXN];
ull a[2][MAXN],ans;
int T,n,q;
void build(int flag,int num,int L,int R){
    l(flag,num)=L;
    r(flag,num)=R;
    if(L==R){
        maxn(flag,num)=a[flag][L];
        return;
    }
    int mid=(L+R)>>1;
    build(flag,num*2,L,mid);
    build(flag,num*2+1,mid+1,R);
    maxn(flag,num)=max(maxn(flag,num*2),maxn(flag,num*2+1));
}
ull find(int flag,int num,int L,int R){
    if(L<=l(flag,num)&&r(flag,num)<=R){
        return maxn(flag,num);
    }
    int mid=(l(flag,num)+r(flag,num))>>1;
    ull res=0;
    if(L<=mid) res=max(res,find(flag,num*2,L,R));
    if(R>mid) res=max(res,find(flag,num*2+1,L,R));
    return res;
}
int main(){
#ifdef OFFLINE
    freopen("match.in","r",stdin);
    freopen("match.out","w",stdout);
#endif
    ios::sync_with_stdio(false);
    cin>>T>>n;
    for(int i=1;i<=n;i++){
        cin>>a[0][i];
    }
    for(int i=1;i<=n;i++){
        cin>>a[1][i];
    }
    build(0,1,1,n);
    build(1,1,1,n);
    cin>>q;
    while(q--){
        ans=0;
        int L,R;
        cin>>L>>R;
        for(int i=L;i<=R;i++){
            for(int j=i;j<=R;j++){
                ull a=find(1,1,i,j);
                ull b=find(0,1,i,j);
                ans+=a*b;
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}