#include<bits/stdc++.h>
using namespace std;
int T,n;
unsigned long long ans;
unsigned long long a[256789],b[256789];
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("%llu",a+i);
	for (int i=1; i<=n; ++i)
		scanf("%llu",b+i);
	int Q;
	scanf("%d",&Q);
	while (Q-->0) {
		int l,r;
		scanf("%d%d",&l,&r);
		for (int p = l; p<=r; ++p) {
			unsigned long long maxa = a[p],maxb = b[p];
			for (int q=p; q<=r; ++q) {
				maxa = max(maxa,a[q]);
				maxb = max(maxb,b[q]);
				ans += maxa*maxb;
			}
		}
		printf("%llu\n",ans),ans = 0;
	}
	return 0;
}
