#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
int T, n, q;
ull a[3010], b[3010], f[3010][3010];

int main() {
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> T >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= n; i++)
		cin >> b[i];
	for (int i = 1; i <= n; i++) {
		ull s = a[i], t = b[i];
		for (int j = i; j <= n; j++) {
			s = max(s, a[j]); t = max(t, b[j]);
			f[i][j] = f[i][j - 1] + s * t;
		}
	}
	cin >> q;
	while (q--) {
		int l, r;
		cin >> l >> r;
		ull ans = 0;
		for (int i = l; i <= r; i++)
			ans += f[i][r];
		cout << ans << endl;
	}
	return 0;
}