//how to calculate match???
#include<bits/stdc++.h>
using namespace std;
int m,n,s,cnt,t,q,k;
unsigned long long ans;
int a[500010],b[500010];
int main() {
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%d%d",&t,&n);
	for(int i=1; i<=n; i++) {
		scanf("%d",&a[i]);
	}
	for(int i=1; i<=n; i++) {
		scanf("%d",&b[i]);
	}
	scanf("%d",&q);//i forget how to da st biao le !!
	while(q--) {
		ans=0;
		int l,r;
		scanf("%d%d",&l,&r);
		for(int i=l; i<=r; i++) {
			for(int j=i; j<=r; j++) {
				int m1=-1,m2=-1;
				for(int x=i; x<=j; x++) {
					m1=max(m1,a[x]);
					m2=max(m2,b[x]);
				}
				ans+=m1*m2;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
//no! only 8pts
//i cant accept
