#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
const int N = 3005;
int n, m, T, a[N], b[N], fa[N][N], fb[N][N];
ull sum[N][N];
ull calc(int l1, int r1, int l2, int r2) {
	return sum[l2][r2] - sum[l2][r1 - 1] - sum[l1 - 1][r2] + sum[l1 - 1][r1 - 1];
}

int main() {
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
	scanf("%d%d", &T, &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++)
		scanf("%d", &b[i]);
	for (int i = 1; i <= n; i++) {
		fa[i][i] = a[i], fb[i][i] = b[i];
		for (int j = i + 1; j <= n; j++) {
			fa[i][j] = max(fa[i][j - 1], a[j]);
			fb[i][j] = max(fb[i][j - 1], b[j]);
		}
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			sum[i][j] = sum[i][j - 1] + 1ull * fa[i][j] * fb[i][j];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			sum[i][j] += sum[i - 1][j];
	scanf("%d", &m);
	while (m--) {
		int l, r;
		scanf("%d%d", &l, &r);
		printf("%llu\n", calc(l, l, r, r));
	}
	return 0;
}