#include<bits/stdc++.h>
#define ll unsigned long long
#define N 250005
using namespace std;

ll ans;
int a[N],b[N],id_a[N],id_b[N],maxn_a[N][20],maxn_b[N][20];
int lg[N],T,n,q;

inline int query_a(const int& l,const int& r)
{
	int k=lg[r-l+1];
	return max(maxn_a[l][k],maxn_a[r-(1<<k)+1][k]);
}

inline int query_b(const int& l,const int& r)
{
	int k=lg[r-l+1];
	return max(maxn_b[l][k],maxn_b[r-(1<<k)+1][k]);
}

ll DFS(const int& l,const int& r)
{
	if(l>r)
		return 0;
	
	if(l==r)
		return a[l]*b[l];
	
	int max_a=query_a(l,r),
	max_b=query_b(l,r);
	
	int nl=min(id_a[max_a],id_b[max_b]),
	nr=max(id_a[max_a],id_b[max_b]);
	
	ll ans=0;
	ans+=DFS(l,nr-1);
	ans+=DFS(nl+1,r);
	ans-=DFS(nl+1,nr-1);
	
	return ans+(ll)(nl-l+1)*(r-nr+1)*(max_a*max_b);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	
	lg[1]=0;
	for(int i=2;i<N;i++)
		lg[i]=lg[i>>1]+1;
	
	cin>>T>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i],id_a[a[i]]=i,maxn_a[i][0]=a[i];
	
	for(int i=1;i<=n;i++)
		cin>>b[i],id_b[b[i]]=i,maxn_b[i][0]=b[i];
	
	for(int j=1;j<20;j++)
		for(int i=1;i<=n;i++)
			maxn_a[i][j]=max(maxn_a[i][j-1],maxn_a[i+(1<<(j-1))][j-1]);
	
	for(int j=1;j<20;j++)
		for(int i=1;i<=n;i++)
			maxn_b[i][j]=max(maxn_b[i][j-1],maxn_b[i+(1<<(j-1))][j-1]);
	
	int l,r;
	cin>>q;
	while(q--)
	{
		cin>>l>>r;
		ans=DFS(l,r);
		cout<<ans<<endl;
	}
}
