#include <cmath>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int dlog2[500000], f[3][500000][20], a[500000], b[500000], id, n, l, r;
void deal_rmq() {
	for (int i = 2; i <= 2 * n; i++)
		dlog2[i] = dlog2[i / 2] + 1;
	
	for (int i = 1; i <= n; i++)
		f[1][i][0] = a[i], f[2][i][0] = b[i];
	
	for (int type = 1; type <= 2; type++)
		for (int j = 1; j <= dlog2[n] + 1; j++)
			for (int i = 1; i <= n; i++)
				f[type][i][j] = max(f[type][i][j - 1], f[type][i + (1 << (j - 1))][j - 1]);
}

unsigned long long select_maxx(int type, int l, int r) {
	int len = r - l + 1;
	return max(f[type][l][dlog2[len]], f[type][r - (1 << dlog2[len]) + 1][dlog2[len]]);
}

int main() {
  freopen("match.in", "r", stdin);
  freopen("match.out", "w", stdout);
	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]);
	
	deal_rmq();
	int Q;
	scanf("%d", &Q);
	unsigned long long ans;
	
	while (Q--) {
		scanf("%d %d", &l, &r);
		ans = 0;
		
		for (int p = l; p <= r; p++)
			for (int q = p; q <= r; q++) {
				unsigned long long x1 = select_maxx(1, p, q), x2 = select_maxx(2, p, q);
				ans += x1 * x2;
			}
				
		printf("%llu\n", ans);
	}
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}

