#include<cstdio>
#include<algorithm>
int n, q, a[200005], b[200005], T; unsigned long long s[3003][3003];
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);
	scanf("%d", &q);
	for (int i = 1; i <= n; i++) {
		int mx = 0, mn = 0;
		for (int j = i; j <= n; j++) {
			mx = std::max(mx, a[j]);
			mn = std::max(mn, b[j]);
			s[i][j] = 1ull * mx * mn + s[i][j - 1];
		}
	}
	while (q--) {
		int l, r; scanf("%d%d", &l, &r);
		unsigned long long ans = 0;
		for (int i = l; i <= r; i++) {
			ans += s[i][r];
		}
		printf("%llu\n", ans);
	}
}
