#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
using namespace std;
bool st;
const int MAXN=2e5+5e4+5;
int t ,n,q;
unsigned long long a[MAXN],b[MAXN];
unsigned long long ans;
//unsigned long long tmp1[MAXN],tmp2[MAXN],t3[MAXN],t4[MAXN];
bool ed;
/*void cdq(int l,int r)
{
	if (l==r)
	{
		ans+=a[l]*b[l];
		return ;
	}
	int mid=(l+r)>>1;
	cdq(l,mid);
	cdq(mid+1,r);
	int pos1=r,pos2=r;
//	unsigned long long mx1=tmp,mx2=tmp1[l];
	for (int i=l;i<=mid;i++)
	{
		mx1=max(mx1,tmp[l]);
		mx2=max(mx2,tmp[r]);
	}
	t3[mid]=t4[mid]=0;
	for (int i=mid+1;i<=r;i++)
	{
		if (mx1<tmp1[i] && pos1==r)
		{
			pos1=i;
			break;
		}
		t3[]
	}
	for (int i=mid+1;i<=r;i++)
	{
		if (mx2<tmp2[i] && pos2==r)
		{
			pos2=i;
			break;
		}
	}
	if (pos1<pos2)
}*//*
struct node
{
	int l, r , val,id;
} tmp1[MAXN],tmp2[MAXN];
int sta[MAXN],top;*/
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
//	printf("%d",(sizeof(a)+sizeof(b))*3/1024/1024);
	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]);
	/*for (int i=1;i<=n;i++)
		tmp[i].l =1,tmp[i].r =n,tmp[i].id =i,tmp[i].val =a[i];
	for (int i=1;i<=n;i++)
	{
		while (top && a[sta[top]]<a[i])
		{
			tmp1[sta[top]].r =i-1;
			top--;
		}
		sta[++top]=i;
	}
	top=0;
	for (int i=n;i>=1;i--)
	{
		while (top &&a[sta[top]]<a[i])
		{
			tmp1[sta[top]].r =i+1;
			top--;
		}
		sta[++top]=i;
	}
	top=0;
	for (int i=1;i<=n;i++)
	{
		while (top && b[sta[top]]<b[i])
		{
			tmp2[sta[top]].r =i-1;
			top--;
		}
		sta[++top]=i;
	}
	top=0;
	for (int i=n;i>=1;i--)
	{
		while (top &&a[sta[top]]<a[i])
		{
			tmp2[sta[top]].r =i+1;
			top--;
		}
		sta[++top]=i;
	}*/
	scanf("%d",&q);
	for (int i=1;i<=q;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		ans=0;
		if (n<=3000)
		{
			for (int i=l;i<=r;i++)
			{
				unsigned long long mx1=0,mx2=0;
				for (int j=i;j<=r;j++)
				{
					mx1=max(mx1,a[j]);
					mx2=max(mx2,b[j]);
					ans+=mx1*mx2;
				}
			}
		}
		printf("%llu\n",ans);
	}
	return 0;
}