#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
ull read()
{
	ull x=0;
	char ch = getchar();
	while (ch > '9' || ch < '0')
		ch = getchar();
	while (ch <= '9' && ch >= '0')
		{
			x = x*10+ch-'0';
			ch = getchar();
		}
	return x;
}
void write(ull x)
{
	if (x > 9)
		write(x/10);
	putchar(x%10+'0');
}
class Segment_Tree
{
	public:
		ull p[2001000],maxx[8002000];
		void Pushup(ull id)
		{
			maxx[id] = max(maxx[id*2],maxx[id*2+1]);
		}
		void Build(ull l,ull r,ull id)
		{
			if (l == r)
				{
					maxx[id] = p[l];
					return;
				}
			ull mid = (l+r) / 2;
			Build(l,mid,id*2);
			Build(mid+1,r,id*2+1);
			Pushup(id);
		}
		ull Query(ull l,ull r,ull ql,ull qr,ull id)
		{
			if (ql <= l && r <= qr)
				return maxx[id];
			ull mid = (l+r) / 2;
			ull maxn = 0;
			if (ql <= mid)
				maxn = max(maxn,Query(l,mid,ql,qr,id*2));
			if (mid < qr)
				maxn = max(maxn,Query(mid+1,r,ql,qr,id*2+1));
			return maxn;
		}
};
Segment_Tree cpa,cpb;
ull T,n,q,lq,rq,ans;
ull a[2001000],b[2000100];
int main()
{
	//freopen("match3.in","r",stdin);
	
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	
	T = read();
	n = read();
	for (ull i=1;i<=n;++i)
		cpa.p[i] = read();
	for (ull i=1;i<=n;++i)
		cpb.p[i] = read();
	cpa.Build(1,n,1);
	cpb.Build(1,n,1);
	q = read();
	for (ull i=1;i<=q;++i)
		{
			lq = read();
			rq = read();
			ans = 0;
			for (ull j=lq;j<=rq;++j)
				for (ull k=j;k<=rq;++k)
					ans += cpa.Query(1ull,n,j,k,1ull)*cpb.Query(1ull,n,j,k,1ull);
			cout<<ans<<'\n';
		}
	return 0;
}
/*
0 2
2 1
1 2
1
1 2
*/
