#include<bits/stdc++.h>
using namespace std;
#define file(s) freopen(#s".in","r",stdin),freopen(#s".out","w",stdout)
#define ull unsigned ll
#define ll long long
#define il inline
#define cst const
#define ret return
#define gc getchar
#define pc putchar
il ll rd()
{
	ll res=0;int lab=1;char ch=gc();
	while(ch<'0'||ch>'9')lab^=(ch=='-'),ch=gc();
	while((ch>='0')&&(ch<='9'))res=res*10+(ch&15),ch=gc();
	ret lab?res:-res;
}
il void prt(ll x,char tail='\n')
{
	static char s[45];int t=0;
	if(x<0)x=-x,pc('-');
	do{s[++t]=x%10,x/=10;}while(x);
	while(t)pc(s[t--]|48);
	if(tail)pc(tail);
}
ull T,n,a[3005],b[3005],q,l,r,f[3005][3005];
/*
Goodbye OI.

Here buried me.
*/
int main()
{
	file(match);
	T=rd();n=rd();
	for(int i=1;i<=n;++i)a[i]=rd();
	for(int i=1;i<=n;++i)b[i]=rd();
	for(int i=1;i<=n;++i)
	{
		ull ma=a[i],mb=b[i];f[i][i]=ma*mb;
		for(int j=i+1;j<=n;++j)
		{
			ma=max(ma,a[i]);mb=max(mb,a[i]);
			f[i][j]=ma*mb;
		}
	}
	for(int i=1;i<=n;++i)
	{
		for(int j=i+1;j<=n;++j)f[i][j]+=f[i][j-1];
	}
	for(int i=n-1;i>=1;--i)
	{
		for(int j=i;j<=n;++j)f[i][j]+=f[i+1][j];
	}
	q=rd();while(q--)l=rd(),prt(f[l][rd()]);
	ret 0;
}