#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9l+7;
inline long long read() {
    long long x=0;bool f;char ch;
    for(f=0;!isdigit(ch=getchar());f=ch=='-');
    for(x=ch-48;isdigit(ch=getchar());x=x*10+ch-48);
    return f?-x:x;
}
inline void print(unsigned long long x,char las) {
    if(!x) {
        putchar(48),putchar(las);
        return ;
    }
    int ls[40],k=0;
    while(x) ls[++k]=x%10,x/=10;
    while(k) putchar(ls[k--]+48);
    putchar(las);
    return ;
}
int T,n;unsigned long long a[250005],b[250005];
unsigned long long seg1[1000005],seg2[1000005];int ls[1000005],rs[1000005],ss;
inline void build(int x,int l,int r) {
    x=++ss;
    if(l==r) {
        seg1[x]=a[l];seg2[x]=b[l];
        return ;
    }
    int mid=(l+r)>>1;
    ls[x]=ss+1;build(x,l,mid);
    rs[x]=ss+1;build(x,mid+1,r);
    seg1[x]=max(seg1[ls[x]],seg1[rs[x]]);
    seg2[x]=max(seg2[ls[x]],seg2[rs[x]]);
    return ;
}
inline pair<unsigned long long,unsigned long long> query(int x,int l,int r,int L,int R) {
    if(l>R || r<L) return {0,0};
    if(l>=L && r<=R) return {seg1[x],seg2[x]};
    int mid=(l+r)>>1;
    pair<unsigned long long,unsigned long long>rp=query(ls[x],l,mid,L,R),CF=query(rs[x],mid+1,r,L,R);
    return {max(rp.first,CF.first),max(rp.second,CF.second)};
}
int main() {
	freopen("match.in","r",stdin);
	freopen("match.out","r",stdin);
    T=read();n=read();
    for(int i=1;i<=n;i++) a[i]=read();
    for(int i=1;i<=n;i++) b[i]=read();
    int q=read();build(1,1,n);
    while(q--) {
        int l=read(),r=read(),le;le=r-l+1;unsigned long long ans=0;
        for(int len=1;len<=le;len++) {
            for(int ll=l;ll<=r-len+1;ll++) {
                pair<unsigned long long,unsigned long long>pii=query(1,1,n,ll,ll+len-1);
                ans+=pii.first*pii.second;
            }
        }
        print(ans,'\n');
    }
    return 0;
}