#include<bits/stdc++.h>
#define LL long long
#define uLL unsigned long long
using namespace std;
const int N = 3e5 + 10;
uLL a[N],b[N];
int id,n,Q;
int read() {
	int x = 0,f = 1;
	char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-')	f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
	return x * f;
}
int main() {
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	id = read(),n = read();
	for(int i = 1;i <= n;i ++)	a[i] = read();
	for(int i = 1;i <= n;i ++)	b[i] = read();
	Q = read();
	for(int i = 1;i <= Q;i ++) {
		int l = read(),r = read();
		uLL ans = 0;
		for(int p = l;p <= r;p ++) {
			uLL maxna = a[p],maxnb = b[p];
			for(int q = p;q <= r;q ++) {
				maxna = max(maxna,a[q]);
				maxnb = max(maxnb,b[q]);
				ans += maxna * maxnb;
			}
		}
		cout << ans << endl;
	}
	return 0;
}