#include <bits/stdc++.h>
using namespace std;


const int N = 250005;

int id;
int n;
unsigned long long a[2][N];

struct node
{
	int l,r;
	unsigned long long d;
}t[N<<2][2];
#define mid (t[p][id].l+t[p][id].r>>1)
void build(int l,int r,int p,int id)
{
	t[p][id].l = l , t[p][id].r = r;
	if ( l == r )
	{
		t[p][id].d = a[id][l];
		return;
	}
	build(l,mid,p<<1,id);
	build(mid+1,r,p<<1|1,id);
	t[p][id].d = max(t[p<<1][id].d,t[p<<1|1][id].d);
}
unsigned long long ask(int l,int r,int p,int id)
{
	if ( l <= t[p][id].l && t[p][id].r <= r ) return t[p][id].d;
	unsigned long long v = 0;
	if ( l <= mid ) v = max(v,ask(l,r,p<<1,id));
	if ( r > mid ) v = max(v,ask(l,r,p<<1|1,id));
	return v;
}
unsigned long long ans;
void solve1()
{
	int l,r;
	scanf("%d%d",&l,&r);
	ans = 0;
	for ( int p = l ; p <= r ; p++ )
	{
		for ( int q = p ; q <= r ; q++ )
		{
			ans += ask(p,q,1,0)*ask(p,q,1,1);
		}
	}
	printf("%llu\n",ans);
}
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%d%d",&id,&n);
	for ( int i = 1 ; i <= n ; i++ ) scanf("%llu",a[0]+i);
	for ( int i = 1 ; i <= n ; i++ ) scanf("%llu",a[1]+i);
	build(1,n,1,0);
	build(1,n,1,1);
	int Q;
	scanf("%d",&Q);
	while ( Q-- ) solve1();
	
	
	return 0;
}