#include<iostream>
#include<cstdio>
#define int long long
#define ull unsigned long long
using namespace std;
const int N=3010;
int T,n,q;
int f[N][N];
int a[N],b[N];
ull ans[N][N];
int MAX(int x,int y){return x>y?x:y;}
signed main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%lld%lld",&T,&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++) scanf("%lld",&b[i]);
	for(int i=1;i<=n;i++)
	{
		int mx1=0,mx2=0;
		for(int j=i;j<=n;j++)
		{
			mx1=MAX(mx1,a[j]),mx2=MAX(mx2,b[j]);
			f[i][j]=mx1*mx2;
		}
	}
	for(int len=1;len<=n;len++) for(int i=1;i<=n-len+1;i++)
		ans[i][i+len-1]=ans[i][i+len-2]+ans[i+1][i+len-1]-ans[i+1][i+len-2]+f[i][i+len-1];
	scanf("%lld",&q);
	while(q--){int x,y;scanf("%lld%lld",&x,&y),printf("%llu\n",ans[x][y]);}
	return 0;
}
