#include <bits/stdc++.h>
#define re register
#define ll long long
#define ull unsigned long long
using namespace std;
inline int read() {int ret = 0, flag = 1;char ch = getchar();while(ch < '0' || ch > '9') {if(ch == '-') flag = -1;ch = getchar();}while(ch >= '0' && ch <= '9') {ret = ret * 10 + ch - '0';ch = getchar();} return ret * flag;}
const int N = 2.5e5 + 15;


int a[N], b[N], la[N], lb[N], ra[N], rb[N];
ull c[N], sc[N], s[N];
int n;
int main() {
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
	
	int id = read();
	n = read();
	
	for (re int i=1; i<=n; i++) a[i] = read();
	for (re int i=1; i<=n; i++) b[i] = read();
	for (re int i=1; i<=n; i++) c[i] = a[i] * b[i];
	
	la[1] = lb[1] = 1;
	for (re int i=2; i<=n; i++) {
		if(a[i-1] <= a[i]) la[i] = la[i-1];
		else la[i] = i;
		
		if(b[i-1] <= b[i]) lb[i] = lb[i-1];
		else lb[i] = i;
	}
	
	ra[n] = rb[n] = n;
	for (re int i=n-1; i>=1; i--) {
		if(a[i] >= a[i+1]) ra[i] = ra[i+1];
		else ra[i] = i;
		
		if(b[i] >= b[i+1]) rb[i] = rb[i+1];
		else rb[i] = i;
	}
	
	int Q = read();
	
	if(n <= 30) {
		while(Q --) {
			int l = read();
			int r = read(); ull ans = 0;
			
			for (re int p=l; p<=r; p++) {
				for (re int q=p; q<=r; q++) {
					int mxa = 0, mxb = 0;
					for (re int i=p; i<=q; i++) {
						mxa = mxa > a[i] ? mxa : a[i];
						mxb = mxb > b[i] ? mxb : b[i]; 
					}
					ans += 1ull * mxa * mxb;
				}
			}
			printf("%llu\n", ans);
		}
	} else {
		for (re int i=1; i<=n; i++) sc[i] = sc[i-1] + c[i] * (i+1);
		for (re int i=1; i<=n; i++) s[i] = s[i-1] + c[i];
		while(Q --) {
			int l = read();
			int r = read(); ull ans = 0;
			ans = sc[r] - sc[l-1] - 1ull * l * (s[r] - s[l-1]);
			printf("%llu\n", ans);
		}
	}
	
	return 0;
}
