#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
ull a[250010],b[250010];
ll n;
ull read_(){
	ull x=0;
	char c=0;
	c=getchar();
	while(c<'0'||c>'9'){
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x;
}
void write_(ull x){
	int xx[50];
	memset(xx,0,sizeof(xx));
	int i=1;
	while(x){
		xx[i]=x%10;
		i++;
		x/=10;
	}
	for(ll j=i-1;j>=1;j--){
		char c=xx[j]+'0';
		putchar(c);
	}
	printf("\n");
	return;
}
ull findans(ll p,ll q){
	ull maxa=a[p],maxb=b[p];
	for(ll i=p+1;i<=q;i++){
		if(maxa<a[i]){
			maxa=a[i];
		}
		if(maxa==n){
			break;
		}
	}
	for(ll i=p+1;i<=q;i++){
		if(maxb<b[i]){
			maxb=b[i];
		}
		if(maxb==n){
			break;
		}
	}
	return maxa*maxb;
}
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int T;
	scanf("%d%lld",&T,&n);
	for(ll i=1;i<=n;i++){
		a[i]=read_();
	}
	for(ll i=1;i<=n;i++){
		b[i]=read_();
	}
	ll Q;
	scanf("%lld",&Q);
	while(Q--){
		ll l,r;
		ull ans=0;
		scanf("%lld%lld",&l,&r);
		for(ll p=l;p<=r;p++){
			for(ll q=p;q<=r;q++){
				ans+=findans(p,q);
			}
		}
//		if(ans<0){
//			ans+=ULL_MAX;
//		}
		write_(ans);
	}
	return 0;
}
