#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=pow(2,64);
const int N=2e5+5e4+10;
int n,m,T,q,l,r;
int a[N],b[N];
int main(){
	freopen("match.in","r",stdin);	
	freopen("match.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>T>>n;
	for(int i=1;i<=n;i+=1)cin>>a[i];
	for(int i=1;i<=n;i+=1)cin>>b[i];
	cin>>q;
	while(q--){
		cin>>l>>r;ll ans=0;
		for(int i=l;i<=r;i+=1){
			ll _a=a[i],_b=b[i];
			for(int j=i;j<=r;j+=1){
				_a=max(_a,(ll)a[j]);
				_b=max(_b,(ll)b[j]);
				ans+=(_a*_b%mod);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}