#define PROBLEM "match"
#ifndef EVIL_X8E0R2O9N8
#include <fstream>
std::ifstream Xin(PROBLEM ".in");
std::ofstream Xout(PROBLEM ".out");
#else
#define Xin cin
#define Xout cout
#endif
typedef signed long long u64; // Unsigned 64-bit integer.
#include <iostream>
using namespace std;
int a[100000], b[100000];
int main() {
	int T, n;
	Xin >> T >> n;
	for (int i = 0; i < n; i++) { Xin >> a[i]; }
	for (int i = 0; i < n; i++) { Xin >> b[i]; }
	int Q;
	Xin >> Q;
	for (int i = 0; i < Q; i++) {
		int l, r;
		Xin >> l >> r;
		u64 result = 0;
		for (int p = l; p < r; p++) {
			for (int q = p; q < r; q++) {
				u64 aMax = 0, bMax = 0;
				for (int x = p; x <= q; x++) {
					if (aMax < a[x]) { aMax = a[x]; }
				}
				for (int x = p; x <= q; x++) {
					if (bMax < b[x]) { bMax = b[x]; }
				}
				result += (aMax * bMax);
			}
		}
		Xout << result << '\n';
	}
}