#include <bits/stdc++.h>

int a[5005], b[5005];

int main () {
	std::ios::sync_with_stdio (false);
	std::cin.tie (nullptr), std::cout.tie (nullptr);
	freopen ("match.in", "r", stdin);
	freopen ("match.out", "w", stdout);
	int T, n;
	std::cin >> T >> n;
	for (int i = 1; i <= n; i++) std::cin >> a[i];
	for (int i = 1; i <= n; i++) std::cin >> b[i];
	int Q;
	std::cin >> Q;
	while (Q--) {
		int l, r;
		std::cin >> l >> r;
		unsigned long long ans = 0;
		for (int p = l; p <= r; p++) {
			int mxa = a[p], mxb = b[p];
			for (int q = p; q <= r; q++) {
				mxa = std::max (mxa, a[q]);
				mxb = std::max (mxb, b[q]);
				ans = ans + 1ull * mxa * mxb;
			}
		}
		std::cout << ans << '\n';
	}
	return 0;
}