#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define inf 0x3f3f3f3f
const int N=2.5e5+3;
ull ans;
int T,n,Q;
int a[N],b[N];
struct tree {
	int l,r;
	int maxn;
} tr[N<<2],tr1[N<<2];

inline void pushup1(int i) {
	tr1[i].maxn=max(tr1[i<<1].maxn,tr1[i<<1|1].maxn);
}

inline void build1(int i,int l,int r) {
	tr1[i].l=l;
	tr1[i].r=r;
	if(l==r) {
		tr1[i].maxn=b[l];
		return ;
	}
	int mid=(l+r)>>1;
	build1(i<<1,l,mid);
	build1(i<<1|1,mid+1,r);
	pushup1(i);
}

inline ll query1(int i,int l,int r) {
	if(l<=tr1[i].l&&tr1[i].r<=r) {
		return tr1[i].maxn;
	}
//	if(l==r) {
//		return b[l];
//	}
	int mid=(tr1[i].l+tr1[i].r)>>1;
	if(r<=mid) {
		return query1(i<<1,l,r);
	} else if(l>mid) {
		return query1(i<<1|1,l,r);
	} else return max(query1(i<<1,l,r),query1(i<<1|1,l,r));
}

inline void pushup(int i) {
	tr[i].maxn=max(tr[i<<1].maxn,tr[i<<1|1].maxn);
}

inline void build(int i,int l,int r) {
	tr[i].l=l;
	tr[i].r=r;
	if(l==r) {
		tr[i].maxn=a[l];
		return ;
	}
	int mid=(l+r)>>1;
	build(i<<1,l,mid);
	build(i<<1|1,mid+1,r);
	pushup(i);
}

inline ll query(int i,int l,int r) {
	if(l<=tr[i].l&&tr[i].r<=r) {
		return tr[i].maxn;
	}
//	if(l==r) {
//		return a[l];
//	}
	int mid=(tr[i].l+tr[i].r)>>1;
	if(r<=mid) {
		return query(i<<1,l,r);
	} else if(l>mid) {
		return query(i<<1|1,l,r);
	} else {
		return max(query(i<<1,l,r),query(i<<1|1,l,r));
	}

}
signed main() {
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%d%d",&T,&n);
	for(int i=1; i<=n; ++i) {
		scanf("%d",&a[i]);
	}
	for(int i=1; i<=n; ++i) {
		scanf("%d",&b[i]);
	}
//	for(int i=1;i<=n;++i){
//		cout<<a[i]<<" ";
//	}
//	cout<<"\n";
//	for(int i=1;i<=n;++i){
//		cout<<b[i]<<" ";
//	}
//	cout<<"\n";
	build(1,1,n);//a
	build1(1,1,n);//b
	scanf("%d",&Q);
	for(int l,r,i=1; i<=Q; ++i) {
		ans=0;
		scanf("%d%d",&l,&r);
//		cout<<"\n";
		for(int j=l; j<=r; ++j) {
			for(int k=j; k<=r; ++k) {
//				cout<<j<<" "<<k<<":";
//				cout<<query(1,j,k)<<" "<<query1(1,j,k)<<"\n";
				ans=ans+query(1,j,k)*query1(1,j,k);
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}
/*
0 2
2 1
1 2
1
1 2


*/