#include<bits/stdc++.h>
#define N 250010
#define lgN 20
using namespace std;
typedef unsigned long long ll;
inline ll rl(){
	ll ans=0;char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')ans=ans*10+c-'0',c=getchar();
	return ans;
}
ll T,n,q,a[N],b[N];
ll f[N][lgN],g[N][lgN];
ll l[N];
void init(){
	ll x=0;
	for(ll i=1;i<=n;i++){
		if(i>=1<<(x+1))x++;
		l[i]=x;
	}
	for(ll i=n;i>=1;i--){
		f[i][0]=a[i],g[i][0]=b[i];
		for(ll j=1;i+(1<<(j-1))<=n;j++){
			f[i][j]=max(f[i][j-1],f[i+(1<<(j-1))][j-1]);
			g[i][j]=max(g[i][j-1],g[i+(1<<(j-1))][j-1]);
		}
	}
}
ll qra(ll a,ll b){
	return max(f[a][l[b-a]],f[b-(1<<l[b-a])+1][l[b-a]]);
}
ll qrb(ll a,ll b){
	return max(g[a][l[b-a]],g[b-(1<<l[b-a])+1][l[b-a]]);
}
ll x,y,add;
signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	T=rl(),n=rl();
	for(ll i=1;i<=n;i++)a[i]=rl();
	for(ll i=1;i<=n;i++)b[i]=rl();
	init();
	q=rl();
	while(q--){
		x=rl(),y=rl();
		if(x>y)swap(x,y);
		add=0;
		for(ll p=x;p<=y;p++){
			for(ll q=p;q<=y;q++){
				add+=qra(p,q)*qrb(p,q);
			}
		}
		printf("%lld\n",add);
	}
	return 0;
}
