#include<cstdio>
#define ull unsigned long long
using namespace std;
int a[250005], b[250005];
int main()
{
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
	int t, n, q, l, r;
	ull ans, mx1, mx2;
	scanf("%d", &t);
	scanf("%d", &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);
	for(int i = 1; i <= q; i++)
	{
		ans = 0;
		scanf("%d%d", &l, &r);
		for(int j = l; j <= r; j++)
		{
			mx1 = mx2 = 0;
			for(int k = j; k <= r; k++)
			{
				if((int)mx1 < a[k]) mx1 = a[k];
				if((int)mx2 < b[k]) mx2 = b[k];
				ans += mx1 * mx2;
			}
		}
		printf("%llu", ans);
	}
	return 0;
}
