#include<bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
const int MAXN=500005;
const int mod=(1e9+7);

inline int read(int t=0,bool f=1,char c=0){
    while(!isdigit(c=getchar())) f=c^45;
    while(isdigit(c)) t=(t<<1)+(t<<3)+(c^48) , c=getchar();
    return f?t:-t;
}



ull a[MAXN],b[MAXN];

int main(){

    freopen("match.in","r",stdin);
    freopen("match.out","w",stdout);

    int T,n;
    cin>>T>>n;
    for(int i=1;i<=n;++i){
        a[i]=read();
    }
    for(int i=1;i<=n;++i){
        b[i]=read();
    }
    int Q;
    cin>>Q;
    while(Q--){
        int l,r;
        l=read();
        r=read();
        ull res=0;
        for(int i=l;i<=r;++i){
         ull maxa=0,maxb=0;
            for(int j=i;j<=r;++j){
                maxa=max(maxa,a[j]);
                maxb=max(maxb,b[j]);
                res+=maxa*maxb;
                
            }
        }
        cout<<res<<endl;;        
    }


    return 0;
}