#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
ull ans;
const int MAX=250005;
int t,n,m,l,r;
int a[MAX],b[MAX];
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",&m);
	while(m--) {
		scanf("%d%d",&l,&r);
		ans=0;
		int ta,tb,sb;
		for(int p=l;p<=r;p++){
			ta=a[p];
			tb=b[p];
			for(int q=p;q<=r;q++){
				ta=max(a[q],ta);
				tb=max(b[q],tb);
				ans+=ta*tb;
			}
		}
		printf("%llu\n",ans);
	}
	return 0;
}
