#include<bits/stdc++.h>
using namespace std;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9') f=(ch=='-')?-1:1,ch=getchar();
	while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*f;
}
const int N=250005;
int a[N],b[N];
unsigned long long sum;
void write(unsigned long long x)
{
	if(x>9) write(x/10);
	putchar((x%10)^48);
	return;
}
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int t=read(),n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=n;i++) b[i]=read();
	int q=read();
	while(q--)
	{
		sum=0;
		int l=read(),r=read();
		for(int j=l;j<=r;j++)
		{
			int maxa=0,maxb=0;
			for(int i=j;i<=r;i++) maxa=max(maxa,a[i]),maxb=max(maxb,b[i]),sum+=1ll*maxa*maxb/*,cout<<maxa<<' '<<maxb<<' '<<sum<<endl*/;
		}
		write(sum),puts("");
	}
	return 0;
}
/*
0 2
6 17
29 30
1
1 2
*/