#include <bits/stdc++.h>
using namespace std;
const int N = 250005;
int t,n,q;
int a[N],b[N];
int main(){
	std::ios::sync_with_stdio(0);
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	cin>>t>>n;
	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,ans=0;
		cin>>l>>r;
		for (int p=l;p<=r;p++)
			for (int q=p;q<=r;q++){
				int max_a=0,max_b=0;
				for (int i=p;i<=q;++i){
					if (a[i]>max_a) max_a=a[i];
					if (b[i]>max_b) max_b=b[i];
				}
				ans+=max_a*max_b;
			}
		cout<<ans<<endl;
	}
	return 0;
}