#include<bits/stdc++.h>
using namespace std;
#define mod 998244353
#define N 3000000
unsigned long long a[N],b[N];
unsigned long long f[1005][1005],ans[1005][1005];
int T,n,Q;
unsigned long long read()
{
    unsigned long long ans=0,f_id=1;
    char ch=getchar();
    while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if (ch=='-') f_id=-1,ch=getchar();
    while (ch>='0'&&ch<='9') ans=ans*10+ch-'0',ch=getchar();
    return ans*f_id;
}
unsigned long long outgs,outj[100];
void write(unsigned long long x)
{
    if (x==0)
    {
        putchar('0');
        return ;
    }
    if (x<0) putchar('-'),x=-x;
    outgs=0;
    while (x)
    {
        outgs++;
        outj[outgs]=x%10;
        x/=10;
    }
    for (int i=outgs;i;--i) putchar(outj[i]+'0');
}

int main()
{
    freopen("match.in","r",stdin);freopen("match.out","w",stdout);
	T=read(),n=read();
	for (int i=1;i<=n;++i) a[i]=read();
	for (int i=1;i<=n;++i) b[i]=read();
	for (int i=1;i<=n;++i) 
	{
		unsigned long long dqa=a[i],dqb=b[i];
		for (int j=i;j<=n;++j)
		{
			dqa=max(dqa,a[j]),dqb=max(dqb,b[j]);
			ans[i][j]=dqa*dqb;
		}
	}
	for (int i=1;i<=n;++i)
	for (int j=1;j<=n;++j)
	f[i][j]=ans[i][j]+f[i-1][j]+f[i][j-1]-f[i-1][j-1];
 	Q=read();
	while (Q)
	{
		Q--;
		unsigned long long l=read(),r=read();
		write(f[r][r]+f[l-1][l-1]-f[r][l-1]-f[l-1][r]),putchar('\n');
	}
    return 0;
}


















