#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fll
#define For(i_,l_,r_) for(int i_=(l_);i_<=(r_);i_++)
#define Rep(i_,l_,r_) for(int i_=(l_);i_>=(r_);i_--)
using namespace std;
#define Ci const int
#define Cl const ll
#define Cul const ull
#define Cc const char
int _l=-1,_p;Ci inS=1<<18,ouS=1<<18;
char _c[inS],*_u=_c,*_v=_c,_b[ouS],_d[55];
#define getchar() (_u==_v&&(_v=(_u=_c)+fread(_c,1,inS,stdin),_u==_v)?EOF:*_u++)
#define _c_ getchar()
template<typename T=int>inline T read(){
	char ch=_c_;T X=0;bool fl=0;while(ch<48||ch>57)fl|=(ch==45),ch=_c_;
	while(ch>47&&ch<58)X=X*10+(ch^48),ch=_c_;return fl?-X:X;
}
inline char Gec(){
	char ch=_c_;while(ch<33)ch=_c_;return ch;
}
inline void flush(){fwrite(_b,1,_l+1,stdout);_l=-1;}
inline void _pc(Cc c){if(c!=-1)_b[++_l]=c;}
inline void _chf(){if(_l>(ouS>>1))flush();}
template<typename T=int>inline void write(T x,Cc c=-1){
	if(x<0)_pc(45),x=-x;do{_d[++_p]=(x%10)|48;}while(x/=10);
	do{_b[++_l]=_d[_p];}while(--_p);_pc(c);_chf();
}
inline void write(Cc c){_pc(c);}
inline void puc(Cc c){_pc(c);_chf();}
template<typename T,typename...A>void write(T x,A...a){write(x);write(a...);}
int n;ull a[500005],b[500005],s[5005][5005],t[5005][5005],f[5005][5005];
ull fs[5005][5005];
signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int id=read();n=read();
	For(i,1,n)a[i]=read<ull>();
	For(i,1,n)b[i]=read<ull>();
	For(i,1,n)
		For(j,i,n)s[i][j]=max(s[i][j-1],a[j]);
	For(i,1,n)
		For(j,i,n)t[i][j]=max(t[i][j-1],b[j]);
	For(i,1,n)
		For(j,i,n)f[i][j]=s[i][j]*t[i][j];
	For(i,1,n)
		For(j,i,n)fs[i][j]=fs[i][j-1]+f[i][j];
	int Q=read();
	For(i,1,Q){
		ull ans=0;
		int l=read(),r=read();
		For(I,l,r){
			ans+=fs[I][r];
		}
		write(ans,'\n');
	}
	flush();return 0;
}
