#include<bits/stdc++.h>
using namespace std;
#define LL unsigned long long
#define lson (u<<1)
#define rson (u<<1|1)
LL read() {
	LL x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9') {
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9') {
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}

int n;
#define MAXN 250002
LL a[MAXN],b[MAXN];
inline void work(){
	LL ans=0;
	int l=read(),r=read();
	for(int p=l;p<=r;p++)for(int q=p;q<=r;q++){
		LL maxa=0,maxb=0;
		for(int i=p;i<=q;i++)maxa=max(maxa,a[i]);
		for(int i=p;i<=q;i++)maxb=max(maxb,b[i]);
		ans=ans+maxa*maxb;
	}
	printf("%lld\n",ans);
}
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--)work();
}
