#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long
const int N=250005;
int T,n,q,m,l,r,ans;
int a[N],b[N];
int f[N][25],g[N][25];
int two[N];
int read(){
	int num=0;char c='&';
	while(c<'0' or c>'9'){
		c=getchar();
	}
	while(c>='0' and c<='9'){
		num=(num<<3)+(num<<1)+c-'0';
		c=getchar();
	}
	return num;
}
int query_a(int l,int r){
	int len=two[r-l+1];
	return a[f[l][len]]>a[f[r-(1<<len)+1][len]]? f[l][len]:f[r-(1<<len)+1][len];
}
int query_b(int l,int r){
	int len=two[r-l+1];
	return b[g[l][len]]>b[g[r-(1<<len)+1][len]]? g[l][len]:g[r-(1<<len)+1][len];
}
int solve_b(int l,int amid,int r){
	int mid=query_b(l,r);
	if(mid==amid) return (mid-l+1)*(r-mid+1)*b[mid];
	if(mid<amid) return (mid-l+1)*(r-amid+1)*b[mid]+solve_b(mid+1,amid,r);
	if(mid>amid) return (amid-l+1)*(r-mid+1)*b[mid]+solve_b(l,amid,mid-1);
}
void solve_a(int l,int r){
	if(l>r) return;
	int mid=query_a(l,r);
	ans=ans+a[mid]*solve_b(l,mid,r);
	solve_a(l,mid-1);solve_a(mid+1,r);
}
signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	T=read();n=read();
	for(int i=0,j=1;j<=n;i++,j<<=1) two[j]=i;
	for(int i=1;i<=n;i++) if(!two[i]) two[i]=two[i-1];
	m=two[n];
	for(int i=1;i<=n;i++) a[i]=read(),f[i][0]=i;
	for(int i=1;i<=n;i++) b[i]=read(),g[i][0]=i;
	for(int j=1;j<=m;j++)
		for(int i=1;i<=n;i++){
			f[i][j]=(a[f[i][j-1]]>a[f[i+(1<<(j-1))][j-1]])? f[i][j-1]:f[i+(1<<(j-1))][j-1];
			g[i][j]=(b[g[i][j-1]]>b[g[i+(1<<(j-1))][j-1]])? g[i][j-1]:g[i+(1<<(j-1))][j-1];
		}
	q=read();
	while(q--){
		l=read();r=read();
		ans=0;
		solve_a(l,r);
		printf("%lld\n",ans);
	}	
	return 0;
}