//8pts or so...
#include <bits/stdc++.h>
using namespace std;
//Mod:18446744073709551616
int T, n, a[250005], b[250005], Q;
int main ()
{
	freopen ("match.in", "r", stdin);
	freopen ("match.out", "w", stdout);
	
	scanf ("%d%d", &T, &n);
	for (int i = 1; i <= n; i++)
		scanf ("%d", &a[i]);
	for (int i = 1; i <= n; i++)
		scanf ("%d", &b[i]);
	scanf ("%d", &Q);
	if (T <= 2)
	while (Q--)
	{
		long long ans = 0;
		int l, r;
		scanf ("%d%d", &l, &r);
		for (int i = l; i <= r; i++)
			for (int j = i; j <= r; j++)
			{
				int Max1 = 0, Max2 = 0;
				for (int k = i; k <= j; k++)
					Max1 = max (Max1, a[k]), Max2 = max (Max2, b[k]);
				ans += Max1 * Max2;
			}
		printf ("%lld\n", ans);
	}
	
	return 0;
}

