#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define N 200005

int T, n, q;
ull a[N], b[N], c[N], d[N], res, amx[N], bmx[N], sam[N], sbm[N], s[N];

void cdx(int l, int r) {
	if (l == r) { res += c[l] * d[l]; return; }
	int mid = l + r >> 1;
	cdx(l, mid), cdx(mid + 1, r);
	amx[mid] = bmx[mid] = 0;
	sam[mid] = sbm[mid] = s[mid] = 0;
	for (int i = mid + 1; i <= r; i ++) {
		amx[i] = max(amx[i - 1], c[i]);
		bmx[i] = max(bmx[i - 1], d[i]);
		sam[i] = sam[i - 1] + amx[i];
		sbm[i] = sbm[i - 1] + bmx[i];
		s[i] = s[i - 1] + amx[i] * bmx[i];
	}
	ull cmx = 0, dmx = 0, ans = 0;
	for (int i = mid, j = mid, k = mid; i >= l; i --) {
		cmx = max(cmx, c[i]), dmx = max(dmx, d[i]);
		while (j < r && c[j + 1] < cmx) j ++;
		while (k < r && d[k + 1] < dmx) k ++;
		ans += cmx * dmx * (min(j, k) - mid);
		if (j <= k) {
			ans += (sam[k] - sam[j]) * dmx;
		} else {
			ans += (sbm[j] - sbm[k]) * cmx;
		}
		ans += s[r] - s[max(j, k)];
	}
	res += ans;
}

int main() {
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin >> T >> n;
	for (int i = 1; i <= n; i ++) cin >> a[i];
	for (int i = 1; i <= n; i ++) cin >> b[i];
	cin >> q;
	while (q --) {
		int l, r, m;
		cin >> l >> r, m = r - l + 1;
		for (int i = 1; i <= m; i ++) {
			c[i] = a[i + l - 1];
			d[i] = b[i + l - 1];
		}
		res = 0, cdx(1, m), cout << res << endl;
	}
	return 0;
}