#include<bits/stdc++.h>
using namespace std;
namespace ye
{
#define int unsigned long long
int read()
{
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=(x<<3)+(x<<1)+c-48;
	return x*f;
}
const int N=3e5,inf=1e9;
int a[N],b[N];
int T,n,q;
void solve()
{
	T=read();
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=1;i<=n;i++)
		b[i]=read();
	q=read();
	while(q--)
	{
		int lw=read(),rw=read();
		int sum=0;
		for(int l=lw;l<=rw;l++)
		{
			for(int r=l;r<=rw;r++)
			{
				int amax=0,bmax=0;
				for(int i=l;i<=r;i++)
					amax=max(amax,a[i]);
				for(int i=l;i<=r;i++)
					bmax=max(bmax,b[i]);
				sum+=amax*bmax;
			}
		}
		printf("%llu",sum);
	}
	
}
}
signed main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	ye::solve();
	return 0;
}
