#include <bits/stdc++.h>
#define FOR(x,l,r) for(int x = l; x <= r; ++x)
#define _FOR(x,l,r) for(int x = r; x >= l; --x)
using namespace std;
typedef unsigned long long ull;
//ull is important
const int N = 2.5e5 + 5;
int T, n, Q, a[N], b[N];
ull sum;
struct Segtr
{
	int maxa,maxb;
	#define lc (p << 1)
	#define rc (p << 1 | 1)
}tr[N << 2];
void pushup(int p)
{
	tr[p].maxa = max(tr[lc].maxa, tr[rc].maxa);
	tr[p].maxb = max(tr[lc].maxb, tr[rc].maxb);
}
void build(int p, int l, int r)
{
	if (l == r)
	{
		tr[p].maxa = a[l];
		tr[p].maxb = b[l];
		return;
	}
	int mid = (l + r) >> 1;
	build(lc, l, mid);
	build(rc, mid + 1, r);
	pushup(p);
}
int querya(int p, int l, int r, int ql, int qr)
{
	if (ql <= l && r <= qr) return tr[p].maxa;
	int mid = (l + r) >> 1, ret = 0;
	if (mid >= ql) ret = max(ret,querya(lc, l, mid, ql, qr));
	if (mid < qr) ret = max(ret,querya(rc, mid + 1, r, ql, qr));
	return ret;
}
int queryb(int p, int l, int r, int ql, int qr)
{
	if (ql <= l && r <= qr) return tr[p].maxb;
	int mid = (l + r) >> 1, ret = 0;
	if (mid >= ql) ret = max(ret,queryb(lc, l, mid, ql, qr));
	if (mid < qr) ret = max(ret,queryb(rc, mid + 1, r, ql, qr));
	return ret;
}
int main()
{
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin >> T >> n;
	FOR(i, 1, n) cin >> a[i];
	FOR(i, 1, n) cin >> b[i];
	build(1, 1, n);
	cin >> Q;
	while (Q--)
	{
		sum = 0;
		int l, r;
		cin >> l >> r;
		FOR(i, l, r) FOR(j, i, r) sum += (ull)querya(1, 1, n, i, j) * queryb(1, 1, n, i, j);
		cout << sum << endl;
	}
	return 0;
}