#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define int long long
const int N = 3e3 + 10;
int T, n, Q;
int a[N], b[N];
int sum[N][N];
signed main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	
	scanf ("%lld%lld", &T, &n);
	for (int i = 1; i <= n; i ++ ) scanf("%lld", &a[i]);
	for (int i = 1; i <= n; i ++ ) scanf("%lld", &b[i]);
	for (int i = 1; i <= n; i ++ ) {
		int maxa = 0, maxb = 0;
		for (int j = i; j <= n; j ++ ) {
			maxa = max(maxa, a[j]);
			maxb = max(maxb, b[j]);
			sum[i][j] += sum[i][j - 1] + maxa * maxb;
		}
	}
	scanf ("%lld", &Q);
	int l, r;
	int res = 0;
	while (Q -- ) {
		res = 0;
		scanf ("%lld%lld", &l, &r);
		for (int i = l; i <= r; i ++ ) {
			res += sum[i][r];
		}
		printf("%lld\n", res);
	}
	return 0;
}
/*
0 2
2 1
1 2
1
1 2
*/
