#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define rep(i,l,m) for(int i=l;i<=m;i++)
#define mid ((h+t)/2)
using namespace std;
inline void read(ll &x)
{
	ll f=1;
	char ch=getchar();
	if(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	x*=f;
	return ;
}
inline void write(ll x)
{
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
const int N=2e5+5;
ll t,n;
ll a[N];
ll b[N];
ll v1[N<<4];
ll v2[N<<4];
void updata(ll x)
{
	v1[x]=max(v1[x*2],v1[x*2+1]);
	v2[x]=max(v2[x*2],v2[x*2+1]);
}
void build(ll x,ll h,ll t)
{
	if(h==t)
	{
		v1[x]=a[h];
		v2[x]=b[h];
		return;
	}
	build(x*2,h,mid);
	build(x*2+1,mid+1,t);
	updata(x);
}
ll q1(ll x,ll h,ll t,ll h1,ll t1)
{
	if(h1<=h&&t>=t1)
		return v1[x];
	ll ans=0;
	if(t1<=mid)ans=max(ans,q1(x*2,h,mid,h1,t1));
	else ans=max(ans,q1(x*2+1,mid+1,t,h1,t1));
	return ans;
}
ll q2(ll x,ll h,ll t,ll h1,ll t1)
{
	if(h1<=h&&t>=t1)
		return v2[x];
	updata(x);
	ll ans=0;
	if(t1<=mid)ans=max(ans,q2(x*2,h,mid,h1,t1));
	else ans=max(ans,q2(x*2+1,mid+1,t,h1,t1));
	return ans;
}
int Q;
ll ans;
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	ios::sync_with_stdio(0);
	cin>>t>>n;
	rep(i,1,n)
		cin>>a[i];
	rep(i,1,n)
		cin>>b[i];
	build(1,1,n);
	//cout<<qn(1,1,n,1)<<" "<<qn(1,1,n,2)<<"\n";
	cin>>Q;
	int l,r;
	rep(i,1,Q)
	{
		ans=0;
		cin>>l>>r;
		rep(p,l,r)
		{
			rep(q,p,r)
			{
				ans=ans+q1(1,1,n,p,q)*q2(1,1,n,p,q);
			}
		}
		cout<<ans<<"\n";
	}
}