#include<bits/stdc++.h>
#define lowbit(x) ((x) & (-(x)))
#define ll long long
#define pb push_back
#define Fin(x) freopen(x, "r", stdin)
#define Fout(x) freopen(x, "w", stdout)
#define Fio(x) Fin(x".in"), Fout(x".out")
using namespace std;
const int maxn = 3010;
int T, n, m, a[maxn], b[maxn];
unsigned ll res[maxn][maxn], ans[maxn][maxn], t[maxn][maxn];
void modify(int x, int y, unsigned ll k){
	for(int i = x; i <= n; i += lowbit(i)) for(int j = y; j <= n; j += lowbit(j)) t[i][j] += k;
}
unsigned ll query(int x, int y){
	if(!x || !y) return 0;
	unsigned ll ret = 0;
	ret = ans[x][y];
//	for(int i = x; i >= 1; i -= lowbit(i)) for(int j = y; j >= 1; j -= lowbit(j)) ret += t[i][j];
	return ret;
}
int main(){
	Fio("match");
	scanf("%d%d", &T, &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
	for(int i = 1; i <= n; i++){
		int ma = 0, mb = 0;
		for(int j = i; j <= n; j++){
			ma = max(ma, a[j]), mb = max(mb, b[j]);
			ans[i][j] += 1ull * ma * mb;
		}
	}
	for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) ans[i][j] += ans[i - 1][j];
	for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) ans[i][j] += ans[i][j - 1];
//	for(int i = 1; i <= n; i++) for(int j = i; j <= n; j++) modify(i, j, ans[i][j]);
	scanf("%d", &m);
	while(m--){
		int x, y; scanf("%d%d", &x, &y);
//		printf("%llu\n", query(y, y) - query(x - 1, y) - query(y, x - 1) + query(x - 1, x - 1));
		printf("%llu\n", query(y, y) - query(x - 1, y) - query(y, x - 1) + query(x - 1, x - 1));
//		unsigned ll ret = 0;
//		for(int i = x; i <= y; i++) for(int j = i; j <= y; j++){
//			for(int i = l; i <= r; i++) for(int j = i; j <= r; j++){
//				unsigned ll ma = 0, mb = 0;
//				for(int k = i; k <= j; k++) ma = max(ma, 1ull * a[k]), mb = max(mb, 1ull * b[k]);
//				assert(ans[i][j] == ma * mb);
//				ret += ans[i][j];
//			}
//		}
//		printf("%llu\n", ret);
	}
	return 0;
}

