#include<bits/stdc++.h>
#define ll unsigned long long
#define se second 
#define fi first
using namespace std;
const int N=2.5e5+3;
int n,i,t,q;
map<pair<int,int>,ll> ans;
ll a[N],b[N];
class seg{
	#define lc x<<1
	#define rc x<<1|1
	private:
		pair<ll,int> t[N<<2];
		void pushup(int x){
			t[x]=max(t[lc],t[rc]);
		}
	public:
		void build(ll a[],int l,int r,int x){
			if(l==r){
				t[x]=make_pair(a[l],l);
				return;
			}
			int mid=(l+r)>>1;
			build(a,l,mid,lc);
			build(a,mid+1,r,rc);
			pushup(x);
		}
		pair<ll,int> query(int l,int r,int nl,int nr,int x){
			if(l<=nl&&nr<=r)return t[x];
			auto ans=make_pair(0ull,0);
			int mid=(nl+nr)>>1;
			if(l<=mid)ans=max(ans,query(l,r,nl,mid,lc));
			if(mid<r)ans=max(ans,query(l,r,mid+1,nr,rc));
			return ans;
		}
} t1,t2;
ll work(int l,int r){
	if(l>r)return 0ull;
	if(l==r)return (ll)a[l]*b[l];
	pair<int,int> now=make_pair(l,r);
	if(ans.find(now)!=ans.end())return ans[now];
	pair<ll,int> x1=t1.query(l,r,1,n,1);
	pair<ll,int> x2=t2.query(l,r,1,n,1);
	if(x1.se>x2.se)swap(x1,x2);
	ll an=(ll)(x1.se-l+1ull)*(r-x2.se+1ull);
	an*=x1.fi*x2.fi;
//	cout<<x1.fi<<' '<<x1.se<<'\n';
//	cout<<x2.fi<<' '<<x2.se<<'\n';
	an+=work(x1.se+1,r);
	an+=work(l,x2.se-1);
	an-=work(x1.se+1,x2.se-1);//wrong:
	//23 24
	//24 25
	//24 24 repeat
//	cout<<l<<' '<<r<<' '<<ans<<'\n';
	ans[now]=an;
	return an;
}
#undef int
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
//	system("fc match.out match3.ans");
	cin>>t>>n;//qingkong!!!!!!!!!!!!!!!!!!!!!!!!!!!
	for(i=1;i<=n;++i)
		cin>>a[i]/*,cout<<i<<' '<<a[i]<<'\n'*/;
//	cout<<'\n';
	t1.build(a,1,n,1);
	for(i=1;i<=n;++i)
		cin>>b[i]/*,cout<<i<<' '<<b[i]<<'\n'*/;
//	cout<<'\n';
	t2.build(b,1,n,1);
	cin>>q;
	while(q--){
		int l,r;
		cin>>l>>r;
		cout<<work(l,r)<<'\n';
//		cout<<4*19+23*19+27*19+23*17+27*17+27*2<<' ';
//		cout<<4*19+23*17;
	}
	return 0;
}
/*
100
10
1 8 9 6 5 7 5 2 5 3
7 8 5 4 2 7 8 5 1 2
5
9 8 5 26 52
56 12 36 63 2
*/