#include <bits/stdc++.h>
namespace Qiaoqia { 
constexpr int N = 3005;

int id, a[N], b[N], L[N], R[N], n, q;
uint64_t lma[N][N], sum[N][N];

void main() {
	std::cin >> id >> n;
	for (int i = 1; i <= n; i++) std::cin >> a[i];
	for (int i = 1; i <= n; i++) std::cin >> b[i];
	for (int i = 1; i <= n; i++) L[i] = i - 1, R[i] = i + 1;
	for (int i = 1; i <= n; i++)
		while (L[i] >= 1 && a[L[i]] < a[i]) L[i] = L[L[i]];
	for (int i = n; i >= 1; i--)
		while (R[i] <= n && a[R[i]] < a[i]) R[i] = R[R[i]];
	for (int i = 1; i <= n; i++) {
		int max = 0;
		for (int j = i; j <= n; j++) {
			max = std::max(max, b[j]);
			lma[i][j] = lma[i][j - 1] + max;
		}
	}
	for (int i = 1; i <= n; i++)
		for (int j = i; j >= 1; j--)
			sum[j][i] = sum[j + 1][i] + lma[j][i];
	std::cin >> q;
	while (q--) {
		int l, r;
		std::cin >> l >> r;
		uint64_t ans = 0;
		for (int i = l; i <= r; i++) {
			int le = std::max(l, L[i] + 1), ri = std::min(r, R[i] - 1);
			ans += (sum[le][ri] - sum[le][i - 1] - sum[i + 1][ri]) * a[i];
		}
		std::cout << ans << '\n';
	}
}
}
void _() { std::ios::sync_with_stdio(false), std::cin.tie(nullptr); }
int main() { void IO(); IO(); _(); Qiaoqia::main(); }
void IO() {
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
}

