#include<cstdio>
#define Re register
#define LL unsigned long long
using namespace std;
const int N = 250000 + 10;
struct SegmentTree{
	LL l, r, val;
};
SegmentTree tr1[N << 2], tr2[N << 2];
LL a[N], b[N];
LL T, n, Q, ans;
inline LL read() {
	LL s = 0, f = 1; char c = getchar();
	while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
	while (c >= '0' && c <= '9') s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
	return s * f;
}
inline void write(LL x) {
	if (x < 0) putchar('-'), x = ~(x - 1);
	int s[50], top = 0;
	while (x) s[++top] = x % 10, x /= 10;
	if (!top) s[++top] = 0;
	while (top) putchar(s[top--] + '0');
}
inline LL max(LL x, LL y) { return x > y ? x : y; }
inline void Pushup1(int u) { tr1[u].val = max(tr1[u << 1].val, tr1[u << 1 | 1].val); }
inline void Pushup2(int u) { tr2[u].val = max(tr2[u << 1].val, tr2[u << 1 | 1].val); }
inline void Build1(int u, int l, int r) {
	tr1[u].l = l, tr1[u].r = r;
	if (l == r) { tr1[u].val = a[l]; return; }
	int mid = l + r >> 1;
	Build1(u << 1, l, mid); Build1(u << 1 | 1, mid + 1, r); Pushup1(u);
}
inline void Build2(int u, int l, int r) {
	tr2[u].l = l, tr2[u].r = r;
	if (l == r) { tr2[u].val = b[l]; return; }
	int mid = l + r >> 1;
	Build2(u << 1, l, mid); Build2(u << 1 | 1, mid + 1, r); Pushup2(u);
}
inline LL Query1(int u, int l, int r) {
	if (l <= tr1[u].l && tr1[u].r <= r) return tr1[u].val;
	int mid = tr1[u].l + tr1[u].r >> 1, maxn = 0;
	if (mid >= l) maxn = max(maxn, Query1(u << 1, l, r));
	if (mid < r) maxn = max(maxn, Query1(u << 1 | 1, l, r));
	return maxn;
}
inline LL Query2(int u, int l, int r) {
	if (l <= tr2[u].l && tr2[u].r <= r) return tr2[u].val;
	int mid = tr2[u].l + tr2[u].r >> 1, maxn = 0;
	if (mid >= l) maxn = max(maxn, Query2(u << 1, l, r));
	if (mid < r) maxn = max(maxn, Query2(u << 1 | 1, l, r));
	return maxn;
}
int main() {
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
	T = read(), n = read();
	for (Re int i = 1; i <= n; ++i) a[i] = read();
	for (Re int i = 1; i <= n; ++i) b[i] = read();
	Build1(1, 1, n); Build2(1, 1, n);
	Q = read();
	while (Q--) {
		int l = read(), r = read(); ans = 0;
		for (Re int i = l; i <= r; ++i) {
			for (Re int j = i; j <= r; ++j) {
				ans += Query1(1, i, j) * Query2(1, i, j);
			}
		}
		write(ans), putchar('\n');
	}
	return 0;
}