#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll ;
typedef unsigned long long ull ;
#define REP(i,j,k) for(int i=j;i<=k;++i)
inline int read(){
	int v=0,f=1; char c=getchar();
	while(c<48||57<c){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(48<=c&&c<=57) v=(v<<3)+(v<<1)+(c^48),c=getchar();
	return v*f;
}
inline ll readL(){
	ll v=0,f=1; char c=getchar();
	while(c<48||57<c){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(48<=c&&c<=57) v=(v<<3)+(v<<1)+(c^48),c=getchar();
	return v*f;
}
inline void print(int x){
	if(x>9) print(x/10);
	putchar(x%10+48);
}
inline void printL(ll x){
	if(x>9) printL(x/10);
	putchar(x%10+48);
}
inline void write(int x,char c){
	if(x<0) putchar('-'),x=-x;
	print(x),putchar(c);
}
inline void writeL(ll x,char c){
	if(x<0) putchar('-'),x=-x;
	printL(x),putchar(c);
}
const int N=3e3+5;
int n,a[N],b[N],L,R; ull Ans;
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	read(),n=read();
	REP(i,1,n) a[i]=read();
	REP(i,1,n) b[i]=read();
	for(int Q=read();Q--;){
		L=read(),R=read(),Ans=0;
		REP(p,L,R)
			REP(q,p,R){
				int mxa=0,mxb=0;
				REP(i,p,q)
					mxa=max(mxa,a[i]),mxb=max(mxb,b[i]);
				Ans+=mxa*mxb;
			}
		printf("%llu\n",Ans);
	}
}
