#include <bits/stdc++.h>
#define int unsigned long long
//#define OK
using namespace std;
int read ()
{
    char ch=getchar();
    int flag=1,x=0;
    while (ch<'0' || ch>'9')
    {
    	if (ch=='-') flag=-flag;
    	ch=getchar();
	}
	while (ch>='0' && ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return flag*x;
}
struct segment_tree
{
	int a[1000005];
	void build (int i,int l,int r,int* s)
	{
		if (l>r) return;
		if (l==r) { a[i]=s[l]; return; }
		int mid=(l+r)>>1;
		build (i<<1,l,mid,s);
		build (i<<1|1,mid+1,r,s);
		a[i]=max(a[i<<1],a[i<<1|1]);
	}
	int query (int i,int l,int r,int x,int y)
	{
//		printf ("%d %d %d %d %d %d\n",i,l,r,x,y,a[i]);
		if (y<l || x>r) return 0;
		if (x<=l && y>=r) return a[i];
		int mid=(l+r)>>1;
		return max (query(i<<1,l,mid,x,y),query(i<<1|1,mid+1,r,x,y));
	}
} ta,tb;
int T,n,Q,ans,a[250005],b[250005];
signed main ()
{
#ifdef OK
	freopen ("match.in","r",stdin);
	freopen ("match.out","w",stdout);
#endif
	T=read(); n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=1;i<=n;i++) b[i]=read();
	ta.build(1,1,n,a);
	tb.build(1,1,n,b);
	Q=read();
	while (Q--)
	{
		int l=read(),r=read();
		ans=0;
		for (int p=l;p<=r;p++)
			for (int q=p;q<=r;q++)
			{
				int x=ta.query(1,1,n,p,q);
				int y=tb.query(1,1,n,p,q);
				ans+=x*y;
//				printf ("(%d,%d):%d*%d=%d\n",p,q,x,y,x*y);
			}
		printf ("%llu\n",ans);
//		printf ("%llu\n",f(l,r));
	}
#ifndef OK
	printf ("%d\n",clock());
#endif
	return 0;
}
