#include<bits/stdc++.h>
using namespace std;
int T,n,Q;
int a[250005],b[250005],l[250005],r[250005];
int ma[250005][25],mb[250005][25];
void init(){
	for(int i = 1;i <= n;i++){
		ma[i][0] = a[i];
		mb[i][0] = b[i];
	}
	for(int j = 1;1+(1<<j)-1<=n;j++){
		for(int i = 1;i <= n;i++){
			if(i+(1<<j)-1>n) break;
			ma[i][j] = max(ma[i][j-1],ma[i+(1<<(j-1))][j-1]);
			mb[i][j] = max(mb[i][j-1],mb[i+(1<<(j-1))][j-1]);
		}
	}
}
int RMQa(int left,int right){
	int k = log2(right-left+1);
	return max(ma[left][k],ma[right-(1<<k)+1][k]);
}
int RMQb(int left,int right){
	int k = log2(right-left+1);
	return max(mb[left][k],mb[right-(1<<k)+1][k]);
}
unsigned long long ans = 0;

int main(){
	#ifndef LOCAL
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	#endif
	ios::sync_with_stdio(0);
	cin >> T >> n;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
	}
	for(int i = 1;i <= n;i++){
		cin >> b[i];
	}
	init();
	cin >> Q;
	for(int i = 1;i <= Q;i++){
		cin >> l[i] >> r[i];
	}
	for(int i = 1;i <= Q;i++){
		ans = 0;
		for(int p = l[i];p <= r[i];p++){
			for(int q = p;q <= r[i];q++){
				int aa = RMQa(p,q),bb = RMQb(p,q);
				ans = ans+1ull*aa*bb;
			}
		}
		cout << ans << endl;
	}
	return 0;
}