#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=3005;
int n;
ull s[N][N],a[N],b[N];
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int T;
	cin >> T >> n;
	for(int i=1;i<=n;++i) cin >> a[i];
	for(int i=1;i<=n;++i) cin >> b[i];
	int qcnt; cin >> qcnt;
	for(int i=1;i<=n;++i){
		ull mx1=0,mx2=0;
		for(int j=i;j<=n;++j){
			mx1=max(mx1,a[j]);
			mx2=max(mx2,b[j]);
			s[i][j]=s[i][j-1]+mx1*mx2;
		}
	}
	while(qcnt--){
		int l,r; cin >> l >> r;
		ull ans=0;
		for(int i=l;i<=r;++i)
			ans=ans+s[i][r];
		cout << ans << '\n';
	}
	return 0;
}
