#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define Min(x, y) (x = min(x, y))
#define Max(x, y) (x = max(x, y))
#define fir(x, y, z) for(int x = (y); x <= (z); ++ x)
#define fdr(x, y, z) for(int x = (y); x >= (z); -- x)
#define fre(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

namespace io {
	const int n = 1e6;
	char c, b[n], *i, *j;
	inline char gc() {
		if (i == j) {
			j = (i = b) + fread(b, 1, n, stdin);
			if (i == j) return EOF;
		} return *i ++;
	}
	#define gc getchar
	template <typename T = int>
	inline T read() {
		T s = 0; int x = 0;
		while (!isdigit(c = gc())) x |= c == '-';
		for (; isdigit(c); c = gc())
			s = (s << 1) + (s << 3) + (c & 15);
		return x ? - s : s;
	}
}

using io :: read;

#define ull unsigned long long

const int N = 3005;

ull a[N], b[N], mxa[N][N], mxb[N][N], ans[N][N];

int main() {
	fre(match);
	int T = read(), n = read();
	fir (i, 1, n) mxa[i][i] = a[i] = read();
	fir (i, 1, n) mxb[i][i] = b[i] = read();
	fir (i, 1, n) ans[i][i] = a[i] * b[i];
	fir (t, 2, n) {
		fir (r, t, n) {
			int l = r - t + 1;
			mxa[l][r] = max(a[l], mxa[l + 1][r]);
			mxb[l][r] = max(b[l], mxb[l + 1][r]);
			ans[l][r] = mxa[l][r] * mxb[l][r];
		}
	}
	fir (r, 1, n) {
		fdr (l, r - 1, 1) {
			ans[l][r] += ans[l + 1][r];
		}
	}
	
	int q = read();
	while (q --) {
		int l = read(), r = read();
		ull res = 0;
		fir (i, l, r) {
			res += ans[l][i];
		}
		cout << res << endl;
	}
	return 0;
}
/*
0 2
2 1
1 2
1
1 2

*/