#include<bits/stdc++.h>
#define For(i,x,y) for (int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (int i=(x);i<(y);i++)
#define Dow(i,x,y) for (int i=(x);i>=(y);i--)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define fil(a,b) memset(a,b,sizeof a)
#define all(x) x.begin(),x.end()
#define siz(x) ((int)x.size())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
	ll x=0,f=1;char c=getchar();
	while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
	if (c=='-') f=-1,c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}

const int N = 2.5e5+10;
int T,n,q;
ull a[N],b[N];

struct Tree2{
	int rt,ls[N],rs[N],top,stk[N],fa[N],dep[N],l[N],r[N];
	ull s1[N];
	ull lans1[N],lans2[N],lans3[N],lans4[N];
	ull rans1[N],rans2[N],rans3[N],rans4[N];
	pa mx[N][22];
	inline void dfs(int u){
		dep[u]=dep[fa[u]]+1;
		l[u]=r[u]=u;
		if (ls[u]){
			fa[ls[u]]=u;
			dfs(ls[u]);
			l[u]=l[ls[u]];
			s1[u]+=s1[ls[u]];
		}
		if (rs[u]){
			fa[rs[u]]=u;
			dfs(rs[u]);
			r[u]=r[rs[u]];
			s1[u]+=s1[rs[u]];
		}
		s1[u]+=1ull*b[u]*(u-l[u]+1)*(r[u]-u+1);
	}
	inline void dfs2(int u){
		lans1[u]=lans1[fa[u]];
		lans2[u]=lans2[fa[u]];
		lans3[u]=lans3[fa[u]];
		if (u==ls[fa[u]]){
			int v=fa[u];
			lans1[u]+=s1[rs[v]];
			lans2[u]+=1ull*(r[v]-v+1)*b[v]*v;
			lans3[u]+=1ull*(r[v]-v+1)*b[v];
		}
		lans4[u]=1ull*b[u]*(r[u]-u+1);
		
		rans1[u]=rans1[fa[u]];
		rans2[u]=rans2[fa[u]];
		rans3[u]=rans3[fa[u]];
		if (u==rs[fa[u]]){
			int v=fa[u];
			rans1[u]+=s1[ls[v]];
			rans2[u]+=1ull*(v-l[v]+1)*b[v]*v;
			rans3[u]+=1ull*(v-l[v]+1)*b[v];
		}
		rans4[u]=1ull*b[u]*(u-l[u]+1);
		if (ls[u]) dfs2(ls[u]);
		if (rs[u]) dfs2(rs[u]);
	}
	inline void Build(){
		For(i,1,n){
			while (top&&b[i]>b[stk[top]]){
				ls[i]=stk[top];
				--top;
			}
			if (top) rs[stk[top]]=i;
			stk[++top]=i;
		}
		rt=stk[1];
		dfs(rt);
		dfs2(rt);
		For(i,1,n) mx[i][0]=mp(b[i],i);
		For(j,1,18) For(i,1,n-(1<<j)+1){
			mx[i][j]=max(mx[i][j-1],mx[i+(1<<(j-1))][j-1]);
		}
	}
	inline int LCA(int l,int r){
		int t=__lg(r-l+1);
		return max(mx[l][t],mx[r-(1<<t)+1][t]).se;
	}
	inline ull Query(int l,int r){
		if (l>r) return 0;
		int md=LCA(l,r);
		ull ret=0;
		ret+=1ull*b[md]*(r-md+1)*(md-l+1);
		if (l!=md){
			int lmd2=LCA(l,md-1);
			ret+=lans1[l]-lans1[lmd2];
			ret+=(lans2[l]-lans2[lmd2])-(lans3[l]-lans3[lmd2])*(l-1);
			ret+=lans4[l]+s1[rs[l]];
		}
		if (r!=md){
			int rmd2=LCA(md+1,r);
			ret+=rans1[r]-rans1[rmd2];
			ret+=(rans3[r]-rans3[rmd2])*(r+1)-(rans2[r]-rans2[rmd2]);
			ret+=rans4[r]+s1[ls[r]];
		}
		return ret;
	}
}T2;

struct Tree1{
	int rt,ls[N],rs[N],top,stk[N],fa[N],dep[N],l[N],r[N];
	ull s[N],ycll[N],yclr[N];
	inline void dfs(int u){
		dep[u]=dep[fa[u]]+1;
		l[u]=r[u]=u;
		if (ls[u]){
			fa[ls[u]]=u;
			dfs(ls[u]);
			l[u]=l[ls[u]];
			s[u]+=s[ls[u]];
		}
		if (rs[u]){
			fa[rs[u]]=u;
			dfs(rs[u]);
			r[u]=r[rs[u]];
			s[u]+=s[rs[u]];
		}
		s[u]+=1ull*a[u]*(T2.Query(l[u],r[u])-T2.Query(l[u],u-1)-T2.Query(u+1,r[u]));
		ycll[u]=T2.Query(l[u],u-1);
		yclr[u]=T2.Query(u+1,r[u]);	
	}
	pa mx[N][25];
	inline void Build(){
		For(i,1,n){
			while (top&&a[i]>a[stk[top]]){
				ls[i]=stk[top];
				--top;
			}
			if (top) rs[stk[top]]=i;
			stk[++top]=i;
		}
		rt=stk[1];
		dfs(rt);
		For(i,1,n) mx[i][0]=mp(a[i],i);
		For(j,1,18) For(i,1,n-(1<<j)+1){
			mx[i][j]=max(mx[i][j-1],mx[i+(1<<(j-1))][j-1]);
		}
	}
	inline int LCA(int l,int r){
		int t=__lg(r-l+1);
		return max(mx[l][t],mx[r-(1<<t)+1][t]).se;
	}
	inline ull Query(int ql,int qr){
		ull ret=0;
		int md=LCA(ql,qr);
		if (ql!=md) ret+=s[rs[ql]];
		for (int u=ql;u!=md;u=fa[u]){
			int v=fa[u];
			if (v!=md&&u==ls[v]) ret+=s[rs[v]];
			if (u>=ql&&u<=qr) ret+=1ull*a[u]*(T2.Query(ql,r[u])-T2.Query(ql,u-1)-yclr[u]);
		}
		if (qr!=md) ret+=s[ls[qr]];
		for (int u=qr;u!=md;u=fa[u]){
			int v=fa[u];
			if (v!=md&&u==rs[v]) ret+=s[ls[v]];
			if (u>=ql&&u<=qr) ret+=1ull*a[u]*(T2.Query(l[u],qr)-ycll[u]-T2.Query(u+1,qr));
		}
		ret+=1ull*a[md]*(T2.Query(ql,qr)-T2.Query(ql,md-1)-T2.Query(md+1,qr));
		return ret;
	}
}T1;

int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	T=read(),n=read();
	For(i,1,n) a[i]=read();
	For(i,1,n) b[i]=read();
	T2.Build();
	T1.Build();
	q=read();
	For(i,1,q){
		int l=read(),r=read();
		printf("%llu\n",T1.Query(l,r));
	}
}
