#include<bits/stdc++.h>
#define I inline
#define RI register int
#define N 1000100
#define LL long long 
#define ull unsigned long long 
#define mod 998244353
#define debug puts("debug")
#define mem cout<<abs(&m1-&m2)/1024.0<<1024.0<<endl
using namespace std;
I int read()
{
	RI res=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))res=(res<<1)+(res<<3)+(ch&15),ch=getchar();
	return res*f;
}
ull ans;
int T,n,a[N],b[N];
int main()
{  
	freopen("match.in","r",stdin);freopen("match.out","w",stdout);
	T=read();n=read();
	for(RI i=1;i<=n;i++)a[i]=read();
	for(RI i=1;i<=n;i++)b[i]=read();
	int Q=read();while(Q--){
		ans=0;
		RI l,r;l=read();r=read();
		for(RI p=l;p<=r;p++){
			ull ma=0,mb=0;
			for(RI q=p;q<=r;q++){
				ma=max(ma,(ull)a[q]);
				mb=max(mb,(ull)b[q]);
				ans+=ma*mb;
			}
		}printf("%lld\n",ans);
	}return 0;
}