#include <bits/stdc++.h>
typedef unsigned long long LL;

const int MAXN = 2.5e5 + 5;
int t, n, a[MAXN], b[MAXN];
unsigned long long ans;

int Read()
{
	int sum = 0, fh = 1; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) fh -= (ch == '-') << 1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) sum = (sum << 3) + (sum << 1) + (ch ^ 48);
	return sum * fh;
}
LL Max(LL fir, LL sec) { return (fir > sec) ? fir : sec; }

int main()
{
	freopen("match.in", "r", stdin); freopen("match.out", "w", stdout);
	t = Read(), n = Read();
	for (int i = 1; i <= n; ++i) a[i] = Read();
	for (int i = 1; i <= n; ++i) b[i] = Read();
	int q = Read();
	while (q--)
	{
		int l = Read(), r = Read(); ans = 0;
		for (int i = l; i <= r; ++i)
		{
			unsigned long long Maxn1 = 0, Maxn2 = 0;
			for (int j = i; j <= r; ++j)
			{
				Maxn1 = Max(Maxn1, a[j]); Maxn2 = Max(Maxn2, b[j]);
				ans += Maxn1 * Maxn2;
			}
		}
		std::cout << ans << "\n";
	}
	return 0;
}