#include <cstdio>
#include <iostream>
using namespace std;

#define PNAME "match"

#ifdef LOCAL_TEST
#define FNAME PNAME "3"
#else
#define FNAME PNAME
#endif

const int max_n = 3000;

int a[max_n], b[max_n];
unsigned long long ans[max_n + 1][max_n + 1];

inline void chmax(int &x, int y) { if (x < y) x = y; }
signed main()
{
	freopen(FNAME ".in", "r", stdin);
	freopen(FNAME ".out", "w", stdout);
	
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int id, n;
	
	cin >> id >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> b[i];
	
	for (int i = 0; i < n; i++)
		for (int j = i, mxa = 0, mxb = 0; j < n; j++)
		{
			chmax(mxa, a[j]);
			chmax(mxb, b[j]);
			ans[i + 1][j + 1] = 1ll * mxa * mxb;
			// cerr << i << " " << j << " " << mxa << " " << mxb << endl;
		}
	
	for (int i = 0; i <= n; i++)
		for (int j = 0; j < n; j++)
			ans[i][j + 1] += ans[i][j];
	for (int j = 0; j <= n; j++)
		for (int i = 0; i < n; i++)
			ans[i + 1][j] += ans[i][j];
	
	int q, l, r;
	cin >> q;
	while (q--)
	{
		cin >> l >> r;
		cout << ans[r][r] - ans[r][l - 1] - ans[l - 1][r] + ans[l - 1][l - 1] << "\n";
	}
	
	return 0;
}