#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define init(x) memset (x,0,sizeof (x))
#define INF 0x3f3f3f3f
using namespace std;
const int MAX = 1e5 + 5;
inline int read ();
int t,n,q,a[MAX],b[MAX];ull ans,ta[MAX << 2],tb[MAX << 2];
void build (ull tree[],int cur,int l,int r,int ty);
ull query (ull tree[],int cur,int l,int r,int x,int y);
int main ()
{
	freopen ("match.in","r",stdin);
	freopen ("match.out","w",stdout);
	t = read ();n = read ();
	for (int i = 1;i <= n;++i) a[i] = read ();
	for (int i = 1;i <= n;++i) b[i] = read ();
	build (ta,1,1,n,0);build (tb,1,1,n,1);
	q = read ();
	while (q--)
	{
		int l = read (),r = read ();ans = 0;
		for (int i = l;i <= r;++i)
			for (int j = i;j <= r;++j) 
				ans += query (ta,1,1,n,i,j) * query (tb,1,1,n,i,j);
		printf ("%llu\n",ans);
	}
	return 0;
}
inline int read ()
{
	int s = 0,f = 1;
	char ch = getchar ();
	while ((ch < '0' || ch > '9') && ch != EOF)
	{
		if (ch == '-') f = -1;
		ch = getchar ();
	}
	while (ch >= '0' && ch <= '9')
	{
		s = s * 10 + ch - '0';
		ch = getchar ();
	}
	return f * s;
}
void build (ull tree[],int cur,int l,int r,int ty)
{
	if (l == r)
	{
		tree[cur] = (!ty) ? a[l] : b[l];
		return ;
	}
	int mid = (l + r) >> 1;
	build (tree,cur << 1,l,mid,ty);build (tree,cur << 1 | 1,mid + 1,r,ty);
	tree[cur] = max (tree[cur << 1],tree[cur << 1 | 1]);
}
ull query (ull tree[],int cur,int l,int r,int x,int y)
{
	if (x <= l && y >= r) return tree[cur];
	int mid = (l + r) >> 1;ull s = 0;
	if (x <= mid) s = max (s,query (tree,cur << 1,l,mid,x,y));
	if (y > mid) s = max (s,query (tree,cur << 1 | 1,mid + 1,r,x,y));
	return s;
}
