#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N=300005;
ull ma,mb,a[N],b[N],c[N*4],d[N*4],ans;
int l,r,T,n,Q;
void build1(int k,int l,int r)
{
	if (l==r)
	{
		c[k]=l;
		return;
	}
	int mi=(l+r)>>1;
	build1(k*2,l,mi);
	build1(k*2+1,mi+1,r);
	if (a[c[k*2]]>a[c[k*2+1]]) c[k]=c[k*2];else c[k]=c[k*2+1];
}
void build2(int k,int l,int r)
{
	if (l==r)
	{
		d[k]=l;
		return;
	}
	int mi=(l+r)>>1;
	build2(k*2,l,mi);
	build2(k*2+1,mi+1,r);
	if (b[d[k*2]]>b[d[k*2+1]]) d[k]=d[k*2];else d[k]=d[k*2+1];
}
int querya(int k,int l,int r,int x,int y)
{
	if (l>y||r<x) return 0;
	if (x<=l&&r<=y)
		return c[k];
	int mi=(l+r)>>1;
	int s=querya(k*2,l,mi,x,y);
	int t=querya(k*2+1,mi+1,r,x,y);
	if (a[s]>a[t]) return s;else return t;
}
int queryb(int k,int l,int r,int x,int y)
{
	if (l>y||r<x) return 0;
	if (x<=l&&r<=y)
		return d[k];
	int mi=(l+r)>>1;
	int s=queryb(k*2,l,mi,x,y);
	int t=queryb(k*2+1,mi+1,r,x,y);
	if (b[s]>b[t]) return s;else return t;
}
ull search(int l,int r)
{
	if (l>r) return 0;
	ull res=0;
	int x=querya(1,1,n,l,r);
	int y=queryb(1,1,n,l,r);
	int xx=min(x,y);
	int yy=max(x,y);
	res+=(xx-l+1)*(r-yy+1)*a[x]*b[y];
	res-=search(xx+1,yy-1);
	res+=search(l,yy-1);
	res+=search(xx+1,r);
	return res;
}
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%d%d",&T,&n);
	for (int i=1;i<=n;++i) scanf("%llu",&a[i]);
	for (int i=1;i<=n;++i) scanf("%llu",&b[i]);
	build1(1,1,n);
	build2(1,1,n);
	scanf("%d",&Q);
	while (Q--)
	{
		scanf("%d%d",&l,&r);
		printf("%llu\n",search(l,r));
	}
	return 0;
}
