#include<bits/stdc++.h>
using namespace std;
namespace __Plozia__
{
#define fir first
#define sec second
#define all(x) begin(x),end(x)
typedef unsigned long long ll;
typedef pair<int,int> pii;
template<typename type>
inline void chmax(type &x,const type &y)
{
	if(x<y)
		x=y;
}
template<typename type>
inline void chmin(type &x,const type &y)
{
	if(y<x)
		x=y;
}
constexpr int Max=2.5e5+100;
int a[Max],b[Max],n,m,T;
namespace subtask1
{
	ll f[3010][3010],g[3010][3010];
	void solve()
	{
		for(int i=1;i<=n;++i)
		{
			int x=0,y=0;
			for(int j=i;j;--j)
			{
				chmax(x,a[j]),chmax(y,b[j]);
				f[i][j]=(ll)x*y+f[i][j+1];
			}
		}
		for(int i=1;i<=n;++i)
			for(int j=i;j<=n;++j)
				g[i][j]=g[i][j-1]+f[j][i];
		int l,r;
		while(m--)
			cin>>l>>r,cout<<g[l][r]<<"\n";
		exit(0);
	}
}
int s1[Max],s2[Max];
signed plozia_main()
{
	cin>>T>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	for(int i=1;i<=n;++i)
		cin>>b[i];
	cin>>m;
	if(n<=3000&&m<=3000)
		subtask1::solve();
	int l,r;
	while(m--)
	{
		cin>>l>>r;
		int top1=0,top2=0;
		ll ans=0;
		s1[0]=s2[0]=l-1;
		for(int i=l;i<=r;++i)
		{
			while(top1&&a[s1[top1]]<a[i])
				--top1;
			s1[++top1]=i;
			while(top2&&b[s2[top2]]<b[i])
				--top2;
			s2[++top2]=i;
			int x=top1,y=top2;
			while(x&&y)
			{
				int k=max(s1[x-1],s2[y-1]);
				ans+=(ll)a[s1[x]]*b[s2[y]]*(min(s1[x],s2[y])-k);
				if(s1[x-1]>s2[y-1])
					--x;
				else
					--y;
			}
		}
		cout<<ans<<"\n";
	}
	return 0;
}
}
signed main()
{
	freopen("match.in","r",stdin),freopen("match.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr),cout.tie(nullptr);
	__Plozia__::plozia_main();
	return 0;
}