#include<bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define q1 u << 1
#define q2 u << 1 | 1

using namespace std;

const int M = 3e5 + 10, N = 20;
ull oppp = 1;
int n, m, Q;
int a[M], b[M], lg[M];

struct seg{
	struct node{
		int l, r;
		int mx;
	}tr[M << 2];
	
	void pushup(int u) {
		tr[u].mx = max(tr[q1].mx, tr[q2].mx);
	}
	
	void build(int u, int l, int r, int p[]) {
		tr[u].l = l, tr[u].r = r;
		if (l == r) tr[u].mx = p[l];
		else {
			int mid = l + r >> 1;
			build(q1, l, mid, p);
			build(q2, mid + 1, r, p);
			pushup(u);
		}
	}
	
	int ask(int u, int l, int r) {
		int lu = tr[u].l, ru = tr[u].r;
		if (l <= lu && ru <= r) return tr[u].mx;
		
		int mid = lu + ru >> 1, res = 0;
		if (l <= mid) res = max(res, ask(q1, l, r));
		if (mid < r) res = max(res, ask(q2, l, r));
		
		return res;
	}
	
}t1, t2;

int main() {
	freopen("match.in", "r", stdin);
	freopen("match.out","w",stdout);
	
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	int T, n; cin >> T >> n;
	
	for (int i = 1;i <= n;i ++) {
		cin >> a[i];
	}
	for (int i = 1;i <= n;i ++) {
		cin >> b[i];
	}
	
	t1.build(1, 1, n, a); t2.build(1, 1, n, b);
	
	cin >> Q;
	ull ans = 0;
	while (Q --) {
		ans = 0;
		
		int l, r;
		cin >> l >> r;
		
		for (int p = l;p <= r;p ++) {
			for (int q = p;q <= r;q ++) {
				ans += oppp * t1.ask(1, p, q) * t2.ask(1, p, q);
				
				//printf("%d %d:\n  ", p, q);
				//cout << t1.ask(1, p, q) << ' ' << t2.ask(1, p, q) << '\n'; 
			}
		}
		
		cout << ans << '\n';	
	}

	
	
	return 0;
}