#include <bits/stdc++.h>
using namespace std;
int n, a[3005], b[3005], q, l, r; unsigned long long s[3005][3005];
int main() {
	freopen ("match.in", "r", stdin);
	freopen ("match.out", "w", stdout);
	scanf ("%*d%d", &n);
	for (int i=1; i<=n; i++) scanf ("%d", &a[i]);
	for (int i=1; i<=n; i++) scanf ("%d", &b[i]);
	for (int i=1; i<=n; i++) {
		int ma = 0, mb = 0;
		for (int j=i; j<=n; j++) {
			ma = max(ma, a[j]), mb = max(mb, b[j]);
			s[i][j] = 1ull * ma * mb;
		}
	}
	for (int i=1; i<=n; i++)
		for (int j=1; j<=n; j++)
			s[i][j] += s[i-1][j] + s[i][j-1] - s[i-1][j-1];
	scanf ("%d", &q);
	while (q --) {
		scanf ("%d%d", &l, &r);
		printf ("%llu\n", s[r][r] - s[l-1][r] - s[r][l-1] + s[l-1][l-1]);
	}
}