#include<bits/stdc++.h>
#define ll long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
using namespace std;
template<typename T_>void operator+=(vector<T_>&x,const T_&y){x.push_back(y);}
const int N=2.5e5+7;
int T,n,q,a[N],b[N];
unsigned ll ans;
void work(int L,int R){
	for(int l=L,mxa,mxb;l<=R;l++){
		mxa=a[l],mxb=b[l];
		ans+=1ll*mxa*mxb;
		for(int r=l+1;r<=R;r++){
			mxa=max(mxa,a[r]),mxb=max(mxb,b[r]);
			ans+=1ll*mxa*mxb;
		}
	}
	cout<<ans<<'\n';
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(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 j=1;j<=n;j++)cin>>b[j];
	cin>>q;
	for(int i=1,l,r;i<=q;i++){
		cin>>l>>r;
		work(l,r);
	}
	return 0;
}

