#include <bits/stdc++.h>
#define int unsigned long long 
using namespace std;
const int N=250005;
int T,n,Q,a[N],b[N],ans;
signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin>>T>>n;
	if (T>=0) {
		for (int i=1;i<=n;i++) cin>>a[i];
		for (int i=1;i<=n;i++) cin>>b[i];
		cin>>Q;
		while (Q--) {
			int L,R; cin>>L>>R;
			ans=0;
			for (int p=L;p<=R;p++) {
				int maxa=a[p],maxb=b[p];
				for (int q=p;q<=R;q++) {
					maxa=max(maxa,a[q]);
					maxb=max(maxb,b[q]);
					ans=ans+maxa*maxb;
				}
			}
			cout<<ans<<'\n';
		}
	}
	return 0;
}
