#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
struct SEG
{
	ull sum[1000010], tg[1000010];
	#define lc(u) (u << 1)
	#define rc(u) (u << 1 | 1)
	inline void Build(int u, int l, int r)
	{
		if(l == r)
		{
			sum[u] = tg[u] = 0;
			return;
		}
		int mid = (l + r) >> 1;
		Build(lc(u), l, mid), Build(rc(u), mid + 1, r);
	}
	inline void pushup(int u)
	{
		sum[u] = sum[lc(u)] + sum[rc(u)];
	}
	inline void pushdown(int u, int l, int r)
	{
		if(!tg[u])
			return;
		sum[lc(u)] = tg[u] * (r - l + 1);
		tg[lc(u)] = tg[u];
		sum[rc(u)] = tg[u] * (r - l + 1);
		tg[rc(u)] = tg[u];
	}
	inline void Modify(int u, int l, int r, int L, int R, ull x)
	{
		if(r < L || R < l)
			return;
		if(L <= l && r <= R)
		{
			tg[u] = x, sum[u] = x * (r - l + 1);
			return;
		}
		pushdown(u, l, r);
		int mid = (l + r) >> 1;
		Modify(lc(u), l, mid, L, R, x), Modify(rc(u), mid + 1, r, L, R, x);
		pushup(u);
	}
	inline ull Query(int u, int l, int r, int L, int R)
	{
		if(r < L || R < l)
			return 0;
		if(L <= l && r <= R)
			return sum[u];
		pushdown(u, l, r);
		int mid = (l + r) >> 1;
		ull ans = Query(lc(u), l, mid, L, R) + Query(rc(u), mid + 1, r, L, R);
		pushup(u);
		return ans;
	}
}A, B;
int a[250010], b[250010];
int main()
{
//	freopen("D.in", "r", stdin);
//	freopen("D.out", "w", stdout);
	int _id, n;
	scanf("%d %d", &_id, &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for(int i = 1; i <= n; i++)
		scanf("%d", &b[i]);
	int q;
	scanf("%d", &q);
	while(q--)
	{
		int l, r;
		scanf("%d %d", &l, &r);
		ull ans = 0;
		for(int i = l; i <= r; i++)
			for(int j = i; j <= r; j++)
			{
				int mx = 0, mmx = 0;
				for(int k = i; k <= j; k++)
					mx = max(mx, a[k]), mmx = max(mmx, b[k]);
				ans += mx * mmx;
			}
		printf("%llu\n", ans);
	}
	return 0;
}