#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define i64 long long
#define u64 unsigned long long
#define pii pair <int,int> 
inline int read(void) {
    int sgn=1,x=0; char c=getchar();
    while(c<'0'||c>'9') { (c=='-'&&(sgn=0)); c=getchar(); }
    while('0'<=c&&c<='9') x=x*10+c-'0',c=getchar();
    return sgn ? x : -x;
}
void write(u64 x) {
    if(x>9) write(x/10),x%=10;
    putchar(x+'0');
}
int T,n,q;
int a[250005],b[250005],Lg[250005];
pii STa[250005][19];
pii STb[250005][19];
u64 Ans;
inline int Qa(int l,int r) {
    int t=Lg[r-l+1];
    return max(STa[l][t],STa[r-(1<<t)+1][t]).first;
}
inline int Qb(int l,int r) {
    int t=Lg[r-l+1];
    return max(STb[l][t],STb[r-(1<<t)+1][t]).first;
}
inline void work(int l,int r,int t=1) {
    if(l>r) return ;
    int m1=Qa(l,r),m2=Qb(l,r);
    int L=min(m1,m2);
    int R=max(m1,m2);
    Ans=Ans+1ull*t*a[m1]*b[m2]*(L-l+1)*(r-R+1);
    work(L+1,r);
    work(l,R-1);
    work(L+1,R-1,-1);
}
signed main() {
    freopen("match.in","r",stdin);
    freopen("match.out","w",stdout);
    T=read(); n=read();
    for(int i=2; i<=n; ++i) Lg[i]=Lg[i>>1]+1;
    for(int i=1; i<=n; ++i) STa[i][0]=make_pair(a[i]=read(),i);
    for(int i=1; i<=n; ++i) STb[i][0]=make_pair(b[i]=read(),i);
    for(int t=0; t<18; ++t) {
        for(int i=1; i+(1<<t)<=n; ++i) {
            STa[i][t+1]=max(STa[i][t],STa[i+(1<<t)][t]);
            STb[i][t+1]=max(STb[i][t],STb[i+(1<<t)][t]);
        }
    }
    q=read();
    for(int i=1,l,r; i<=q; ++i) {
        l=read(); r=read();
        for(int L=l; L<=r; ++L) {
            for(int R=L; R<=r; ++R) {
                Ans=Ans+1ull*Qa(L,R)*Qb(L,R);
            }
        }
        write(Ans); puts("");
        Ans=0;
    }
    return 0;
}