#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 250005;
int TestId, n, Q;
int a[N], b[N];

int main() {
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
	scanf("%d%d", &TestId, &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);
	while (Q--) {
		int l, r; scanf("%d%d", &l, &r);
		ull ans = 0;
		for (int i = l; i <= r; ++i) {
			int mxa = 0, mxb = 0;
			for (int j = i; j <= r; ++j) {
				mxa = max(mxa, a[j]), mxb = max(mxb, b[j]);
				ans += 1ull * mxa * mxb;
			}
		}
		printf("%llu\n", ans);
	}
	fclose(stdin); fclose(stdout);
	return 0;
}
