#include <bits/stdc++.h>
#define int unsigned long long
using namespace std;
signed main() {
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int T,n;
	cin>>T>>n;
	vector<int> a(n+1),b(n+1);
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	int Q;
	cin>>Q;
	for(int i=1;i<=Q;i++) {
		int l,r;
		cin>>l>>r;
		int ans=0;
		for(int p=l;p<=r;p++)
			for(int q=p;q<=r;q++) {
				int maxA=0,maxB=0;
				for(int j=p;j<=q;j++)
					maxA=max(maxA,a[j]);
				for(int j=p;j<=q;j++)
					maxB=max(maxB,b[j]);
				ans+=maxA*maxB;
			}
		cout<<ans<<endl;
	}
	return 0;
}
