#include<bits/stdc++.h>
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=1;--i)
#define N 400005
#define int unsigned long long
using namespace std;

int read(){
	int x=0,w=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*w;
}

int T,n,Q,ans;
int a[N],b[N];

signed main(){
	
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	
	T=read();n=read();
	rep(i,1,n) a[i]=read();
	rep(i,1,n) b[i]=read();
	Q=read();
	while(Q--){
		int l=read(),r=read(); ans=0;
		rep(i,l,r) rep(j,i,r){
			int maxn1=0,maxn2=0;
			rep(k,i,j) maxn1=max(maxn1,a[k]),maxn2=max(maxn2,b[k]);
			ans+=maxn2*maxn1;
		} 
		cout<<ans<<endl;
	}
	return 0;
}
/*
4 4
1 2
2 3
3 1
1 4
*/

