#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e5+5;
int T,n,q,l,r;
int a[N],b[N],st1[N][20],st2[N][20],lg[N];
int main()
{
    freopen("match.in","r",stdin);
    freopen("match.out","w",stdout);
    cin>>T>>n;
    lg[0]=-1;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]),st1[i][0]=a[i],lg[i]=lg[i>>1]+1;
    for(int j=1;j<=n;j++) scanf("%d",&b[j]),st2[j][0]=b[j];
    for(int j=1;j<=lg[n];j++)
        for(int i=1;1+(1<<j)-1<=n;j++)
        {
            st1[i][j]=max(st1[i][j-1],st1[i+(1<<j)][j-1]);
            st2[i][j]=max(st2[i][j-1],st2[i+(1<<j)][j-1]);
        }
    while(q--)
    {
        ll ans=0;
        scanf("%d%d",&l,&r);
        for(int i=l;i<=r;i++)
            for(int j=i;j<=r;j++)
            {
                int len=lg[r-l+1];
                int mxa=max(st1[l][len],st1[r-(1<<len)+1][len]);
                int mxb=max(st2[l][len],st2[r-(1<<len)+1][len]);
                ans=(ans+mxa*mxb);
            }
        printf("%lld\n",ans);
    }
    return 0;
}