#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, m, T;
int read()
{
	int x = 0, f = 1;
	char c = getchar();
	while(c != EOF and !isdigit(c))
	{
		if(c == '-')f = -1;
		c = getchar();
	}
	while(isdigit(c))
	{
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * f;
}
int a[1000010], b[1000010];
signed 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()
		unsigned long long ans = 0;
		for(int i = l;i <= r;i ++)
		{
			for(int j = i;j <= r;j ++)
			{
				int mx = 0, mx1 = 0;
				for(int k = i;k <= j;k ++)
				{
					mx=max(mx, a[k]);
					mx1 = max(mx1, b[k]);
				}
				//cout<<l<<' '<<r<<' '<<mx<<' '<<mx1<<endl;
				ans += (unsigned long long)(mx * mx1);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

