#include<bits/stdc++.h>
using namespace std;

typedef unsigned long long ll;
const ll N=250010;

ll read() {

	ll x=0,f=1;
	char ch=getchar();
	while(ch<48||ch>57) {
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>=48&&ch<=57) {
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	return x*f;

}


ll n,m;
ll anc1[N][54],lgn[N],a[N],b[N],anc2[N][54];

ll query1(ll l,ll r) {
	ll k=lgn[r-l+1];
	return max(anc1[l][k],anc1[r-(1<<k)+1][k]);
}

ll query2(ll l,ll r) {
	ll k=lgn[r-l+1];
	return max(anc2[l][k],anc2[r-(1<<k)+1][k]);
}

ll Q,T;

signed main() {

	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	T=read();
	n=read();

	for(ll i=1; i<=n; i++) a[i]=read(),anc1[i][0]=a[i];
	for(ll i=1; i<=n; i++) b[i]=read(),anc2[i][0]=b[i];

	lgn[0]=lgn[1]=0;
	for(ll i=2; i<=n; i++) lgn[i]=lgn[i/2]+1;
	for(ll j=1; (1<<(j-1))<=n; j++) {

		for(ll i=1; i+(1<<(j-1))-1<=n; i++) {

			anc1[i][j]=max(anc1[i+(1<<(j-1))][j-1],anc1[i][j-1]);
			anc2[i][j]=max(anc2[i+(1<<(j-1))][j-1],anc2[i][j-1]);

		}

	}

	Q=read();
	while(Q--) {

		ll ans=0;
		ll l=read(),r=read();
		for(ll i=1; i<=r-l+1; i++) {

			for(ll j=l; j+i-1<=r; j++) {

				int k=j+i-1;
				ll ma=query1(j,k),mb=query2(j,k);
				ans+=ma*mb;

			}

		}
		cout<<ans<<endl;

	}

	return 0;
}