#include <bits/stdc++.h>
#define rep(i, l, r) for(int i=l, _=r; i<=_; ++i)
typedef long long ll;
typedef unsigned long long ull;
inline int read() {
	int res=0; char ch; bool k=1;
	while(!isdigit(ch=getchar())) k=ch^'-';
	do res=res*10+(ch^48); while(isdigit(ch=getchar()));
	return k? res: -res;
}
const int mN=3e3+9;
bool Mbe;
int T, n, a[2][mN], q;


ull ans[mN][mN];

bool Men;
int main() {
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
//	std::cerr<<"memory: "<<(&Men-&Mbe>>20)<<" MB\n";

	int id=read();
	n=read();
	rep(t, 0, 1) {
		rep(i, 1, n) {
			a[t][i]=read();
		}
	}
	rep(l, 1, n) {
		ull mx0=0, mx1=0;
		rep(r, l, n) {
			if(a[0][r]>mx0) mx0=a[0][r];
			if(a[1][r]>mx1) mx1=a[1][r];
			ans[l][r]=ans[l][r-1]+mx0*mx1;
		}
	}
	for(int l=n; l>=1; --l) {
		rep(r, l, n) {
			ans[l][r]+=ans[l+1][r];
		}
	}
	q=read();
	rep(__, 1, q) {
		int l=read(), r=read();
		printf("%llu\n", ans[l][r]);
	}
	return 0;
}
/*
13+23+5
*/