#include<bits/stdc++.h>
#define For(i,l,r) for(int i=(l);i<=(r);++i)
typedef unsigned long long ull;
const int N=250010;
using namespace std;
int T,n,Q;
int a[N],b[N];
int max_a[N][21],max_b[N][21],log_2[N];
void init()
{
	For(j,1,20)
	{
		for(int i=1;(i+(1<<j)-1)<=n;++i)
		{
			max_a[i][j]=max(max_a[i][j-1],max_a[i+(1<<(j-1))][j-1]);
			max_b[i][j]=max(max_b[i][j-1],max_b[i+(1<<(j-1))][j-1]);
		}
	}
	return;
}
ull query_a(int L,int R)
{
	int k=log_2[R-L+1];
	return 1ull*(max(max_a[L][k],max_a[R-(1<<k)+1][k]));
}
ull query_b(int L,int R)
{
	int k=log_2[R-L+1];
	return 1ull*(max(max_b[L][k],max_b[R-(1<<k)+1][k]));
}
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	log_2[1]=0;
	For(i,2,N-1)
		log_2[i]=log_2[i>>1]+1;
	scanf("%d%d",&T,&n);
	For(i,1,n)
	{
		scanf("%d",&a[i]);
		max_a[i][0]=a[i];
	}
	For(i,1,n)
	{
		scanf("%d",&b[i]);
		max_b[i][0]=b[i];
	}
	init();
	scanf("%d",&Q);
	For(i,1,Q)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		ull res=0;
		For(p,l,r)
		{
			For(q,p,r)
				res+=(1ull*query_a(p,q)*query_b(p,q));
		}
		printf("%llu\n",res);
	}
	return 0;
}