#include<bits/stdc++.h>
#define endl '\n'
#define fir first
#define sec second
#define ri register
#define pb push_back
#define mp make_pair
#define int long long
#define inf 2147483647
#define Swap(x,y) ((x)^=(y)^=(x)^=(y))
#define reset(x,y) memset((x),(y),sizeof((x)))
#define fastcin ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
/* May all the beauty be blessed. */
using namespace std;
inline int read()
{
	ri int x=0,f=0;ri char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c-'0'),c=getchar();
	return f?-x:x;
}
inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
const int N=3e5+10;
int T,n,f[N][21],g[N][21],lg[N];
unsigned int ans;
inline int Queryf(int l,int r) {return max(f[l][lg[r-l+1]],f[r-(1<<lg[r-l+1])+1][lg[r-l+1]]);}
inline int Queryg(int l,int r) {return max(g[l][lg[r-l+1]],g[r-(1<<lg[r-l+1])+1][lg[r-l+1]]);}
signed main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	for(ri int i=2;i<N;++i)
		lg[i]=lg[i>>1]+1;
	T=read(),n=read();
	for(ri int i=1;i<=n;++i)
		f[i][0]=read();
	for(ri int i=1;i<=n;++i)
		g[i][0]=read();
	for(ri int j=1;j<=20;++j)
		for(ri int i=1;i+(1<<j)-1<=n;++i)
			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]);
	for(ri int t=read(),l,r;t;--t)
	{
		l=read(),r=read(),ans=0;
		for(ri int i=l;i<=r;++i)
			for(ri int j=i;j<=r;++j)
				ans+=(unsigned int)Queryf(i,j)*Queryg(i,j);
		cout<<ans<<endl;
	}
	return 0;
}
//O(n^2*Q) 8pts
