#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
const int N=250005;
int n;
ull a[N],b[N],f[N];
int read() {
	int x=0,f=1; char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-48;
	return x*f;
}
int main() {
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	read(); n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=n;i++) b[i]=read();
	for(int q=read();q--;) {
		int l=read(),r=read();
		for(int i=l;i<=r;i++) f[i]=0;
		ull ans=0;
		for(int i=l;i<=r;i++) {
			ull ra=0,rb=0;
			for(int j=i;j>=l;j--) {
				ra=max(ra,a[j]);
				rb=max(rb,b[j]);
				if(j!=i&&a[j]==ra&&b[j]==rb) {
					f[i]+=f[j]; break;
				}
				f[i]+=ra*rb;
			}
			ans+=f[i];
		}
		printf("%llu\n",ans);
	}
	return 0;
}
