//不向抑郁与焦虑投降，这个世界终会有我们存在的地方。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<ctime>
#include<cassert>
#include<tuple>
#define siz(x) int((x).size())
#define all(x) std::begin(x),std::end(x)
#define fi first
#define se second
using std::cin;using std::cout;
using std::min;using std::max;
template<typename any>inline void cmin(any &x,const any &y){if(x>y)x=y;}
template<typename any>inline void cmax(any &x,const any &y){if(x<y)x=y;}
using loli=long long;
using lolu=unsigned long long;
using bsi=std::basic_string<int>;
using bsc=std::string;
template<typename any>inline any get(){any x;cin>>x;return x;}
constexpr int N=2.5e5+1;
int T,n,q;
lolu a[N],b[N];
namespace sub1{
	constexpr int _N=3001,_M=std::__lg(_N)+1;
	lolu s1[_M][_N],s2[_M][_N],f[_N][_N];
	lolu ask1(int l,int r){
		int t=std::__lg(r-l+1);
		return max(s1[t][l],s1[t][r-(1<<t)+1]);
	}
	lolu ask2(int l,int r){
		int t=std::__lg(r-l+1);
		return max(s2[t][l],s2[t][r-(1<<t)+1]);
	}
	lolu calc(int p,int q){
		return ask1(p,q)*ask2(p,q);
	}
	void solve(){
		for(int i=1;i<=n;i++)s1[0][i]=a[i];
		for(int i=1;i<=n;i++)s2[0][i]=b[i];
		for(int i=1;(1<<i)<=n;i++)for(int j=1;j+(1<<i)-1<=n;j++)
			s1[i][j]=max(s1[i-1][j],s1[i-1][j+(1<<(i-1))]);
		for(int i=1;(1<<i)<=n;i++)for(int j=1;j+(1<<i)-1<=n;j++)
			s2[i][j]=max(s2[i-1][j],s2[i-1][j+(1<<(i-1))]);
		for(int p=1;p<=n;p++)
			for(int q=p;q<=n;q++)f[p][q]=calc(p,q)+f[p][q-1];
		for(int l,r;q--;){
			cin>>l>>r;
			lolu res=0;
			for(int p=l;p<=r;p++)
				res+=f[p][r]-f[p][l-1];
			cout<<res<<'\n';
		}
	}
}
signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	std::ios::sync_with_stdio(false);cin.tie(nullptr);
	cin>>T>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)cin>>b[i];
	cin>>q;
	sub1::solve();
	return 0;
}