#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N=2.6e5+999;
int T,n,a[N],b[N],q;
int main() {
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	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;
	int L,R;
	while(q--) {
		cin>>L>>R;
		ull ans=0;
		for(int p=L; p<=R; ++p) {
			for(int q=p; q<=R; ++q) {
				ull maxa=0,maxb=0;
				for(int j=p; j<=q; ++j) {
					maxa=max((ull)a[j],maxa);
					maxb=max((ull)b[j],maxb);
				}
				ans=ans+maxa*maxb;
			}
		}
		cout<<ans<<"\n";
	}
}
/*
0 2
2 1
1 2
1 1 2
*/