#include <bits/stdc++.h>
#define file(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
typedef unsigned long long ull;

const int N = 2e5 + 5;

int id, n, q;
int a[N], b[N];
int la[N], ra[N], lb[N], rb[N];

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	while ('0' > ch or ch > '9') f = ch == '-' ? -1 : 1, ch = getchar();
	while ('0' <= ch and ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return x * f;
}

int main() {
	file("match");
	id = read(), n = read();
	for (int i = 1; i <= n; i ++)
		a[i] = read();
	for (int i = 1; i <= n; i ++)
		b[i] = read();
	for (int i = 1; i <= n; i ++) {
		la[i] = ra[i] = i;
		while (la[i] - 1 >= 1 and a[la[i] - 1] < a[i])
			la[i] --;
		while (ra[i] + 1 <= n and a[ra[i] + 1] < a[i])
			ra[i] ++;
	}
	for (int i = 1; i <= n; i ++) {
		lb[i] = rb[i] = i;
		while (lb[i] - 1 >= 1 and b[lb[i] - 1] < b[i])
			lb[i] --;
		while (rb[i] + 1 <= n and b[rb[i] + 1] < b[i])
			rb[i] ++;
	}
	q = read();
	while (q --) {
		int l = read(), r = read();
		ull ans = 0;
		for (int i = l; i <= r; i ++)
			for (int j = l; j <= r; j ++) {
				int L = std::max(l, std::max(la[i], lb[j])), R = std::min(r, std::min(ra[i], rb[j]));
				if (L > R or std::min(i, j) < L or std::max(i, j) > R)
					continue;
				ans += (R - std::max(i, j) + 1) * (std::min(i, j) - L + 1) * a[i] * b[j];
			}
		printf("%llu\n", ans);
	}
	return 0;
}