#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;

struct node {
	int l, r, v;
} a[1500000], b[1500000];

int T, n, Q;
unsigned long long ans = 0;

void build_a(int k, int l, int r) {
	a[k].l = l;
	a[k].r = r;
	if (l == r) {
		scanf("%d", &a[k].v);
		return ;
	}	
	int mid = (l + r) >> 1;
	build_a(k << 1, l, mid);
	build_a((k << 1) | 1, mid + 1, r);
	a[k].v = max(a[k << 1].v, a[(k << 1) | 1].v);
}

void build_b(int k, int l, int r) {
	b[k].l = l;
	b[k].r = r;
	if (l == r) {
		scanf("%d", &b[k].v);
		return ;
	}	
	int mid = (l + r) >> 1;
	build_b(k << 1, l, mid);
	build_b((k << 1) | 1, mid + 1, r);
	b[k].v = max(b[k << 1].v, b[(k << 1) | 1].v);
}

int query_a(int k, int l, int r) {
	if ((l <= a[k].l) && (a[k].r <= r))
		return a[k].v;
	int mid = (a[k].l + a[k].r) >> 1;
	int res = 0;
	if (l <= mid)
		res = max(res, query_a(k << 1, l, r));
	if (r > mid)
		res = max(res, query_a((k << 1) | 1, l, r));
	return res;
}

int query_b(int k, int l, int r) {
	if ((l <= b[k].l) && (b[k].r <= r))
		return b[k].v;
	int mid = (b[k].l + b[k].r) >> 1;
	int res = 0;
	if (l <= mid)
		res = max(res, query_b(k << 1, l, r));
	if (r > mid)
		res = max(res, query_b((k << 1) | 1, l, r));
	return res;
}

int main() {
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
	scanf("%d %d", &T, &n);
	build_a(1, 1, n);
	build_b(1, 1, n);
	for (scanf("%d", &Q); Q; Q--) {
		ans = 0;
		int l, r;
		scanf("%d %d", &l, &r);
		for (int p = l; p <= r; p++)
			for (int q = p; q <= r; q++) {
				long long x = query_a(1, p, q);
				long long y = query_b(1, p, q);
				ans += x * y;
			}
		cout << ans << "\n" ;
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}