#include<cstdio>
#define db double
#define pc putchar
#define gc getchar
#define ll long long
#define ull unsigned long long
#define Tp template<typename _T>
#define Me(a,b) memset(a,b,sizeof(a))
Tp _T mabs(_T x){ return x>0?x:-x; }
Tp _T mmin(_T x,_T y){ return x<y?x:y; }
Tp _T mmax(_T x,_T y){ return x<y?y:x; }
Tp void mswap(_T &x,_T &y){ _T t=x; x=y; y=t; return; }
Tp void print(_T x){ if(x<0) pc('-'),x=-x; if(x>9) print(x/10); pc(x%10+48); return; }
#define maxn 1039
#define maxm
#define MOD
using namespace std;
#define Type int
Type read(){
	Type sum=0; char c=gc(); int flag=0;
	while(c!='-'&&(c<'0'||c>'9')) c=gc();
	if(c=='-') flag=1,c=gc();
	while('0'<=c&&c<='9') sum=(sum<<1)+(sum<<3)+(c^48),c=gc();
	if(flag) return -sum; else return sum;
}
int n,T,a[maxn],b[maxn],l,r; ull ans,maxx1,maxx2;
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	read(); n=read(); int i,j; for(i=1;i<=n;i++) a[i]=read(); for(i=1;i<=n;i++) b[i]=read();
	T=read(); while(T--){
		l=read(); r=read(); ans=0;
		for(i=l;i<=r;i++){
			maxx1=maxx2=0;
			for(j=i;j<=r;j++){
				maxx1=mmax(maxx1,(ull)a[j]);
				maxx2=mmax(maxx2,(ull)b[j]);
				ans+=maxx1*maxx2;
			}
		} print(ans),pc('\n');
	}
	return 0;
}
