#include <bits/stdc++.h>

using namespace std;

inline int read(){
	int x = 0, f = 1;
	char ch = getchar();
	while (! isdigit(ch)){
		if (ch == '-')
			f = - f;
		ch = getchar();
	}
	while (isdigit(ch)){
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	return x * f;
}

void write(int x){
	if (x < 0){
		putchar('-');
		write(- x);
		return;
	}
	if (x >= 10)
		write(x / 10);
	putchar(x % 10 + 48);
	return;
}

inline void writeln(int x){
	write(x);
	puts("");
	return;
}

inline void writesp(int x){
	write(x);
	putchar(' ');
	return;
}

int n, T;
int a[3005], b[3005];

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();
		int ans = 0;
		for (int p = l; p <= r; ++ p)
			for (int q = p; q <= r; ++ q){
				int ma = 0, mb = 0;
				for (int i = p; i <= q; ++ i){
					ma = max(ma, a[i]);
					mb = max(mb, b[i]);
				}
				ans += ma * mb;
			}
		writeln(ans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
