#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const ll N=1e6+10;
ll a[N],b[N];
ll t,n,q;
ll q1[N],q2[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++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
	}
	cin>>q;
	while(q--){
		ll l,r;
		cin>>l>>r;
		memset(q1,0,sizeof(q1));
		memset(q2,0,sizeof(q2));
		ll sum=0,summ=0;
		for(int i=l;i<=r;i++){
			sum+=1;
			q1[sum]=a[i];
		}
		for(int i=l;i<=r;i++){
			summ+=1;
			q2[summ]=b[i];
		}
		ll ans=0;
		for(int i=1;i<=sum;i++){
			ans+=q1[i]*q2[i];
		}
		for(int i=1;i<=sum;i++){
			for(int j=i+1;j<=sum;j++){
				priority_queue<ll,vector<ll>,less<ll> >heap1;
				priority_queue<ll,vector<ll>,less<ll> >heap2;
				for(int w=i;w<=j;w++){
					heap1.push(q1[w]);
					heap2.push(q2[w]);
				}
				ans+=heap1.top()*heap2.top();
			}
		}
		cout<<ans<<'\n';
	}
	return 0;
}